package com.src.xyzk_personal;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.ini4j.Ini;
import org.ini4j.InvalidFileFormatException;
import org.ini4j.Profile;
import org.ini4j.Profile.Section;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.src.xyzk.bluetooth.service.BluetoothAdapterService;
import com.src.xyzk_personal.EOL.DbAdapter;
import com.src.xyzk_personal.EOL.DbAdapter.TableData;
import com.src.xyzk_personal.EOL.DbAdapter.TableMain;
import com.src.xyzk_personal.EOL.EolFunction;
import com.src.xyzk_personal.config.Common;
import com.src.xyzk_personal.config.CommonXml;
import com.src.xyzk_personal.config.Commonfunc;
import com.src.xyzk_personal.config.Communication;
import com.src.xyzk_personal.config.EcuModule;
import com.src.xyzk_personal.config.HttpRequest;
import com.src.xyzk_personal.config.Communication;
import com.src.xyzk_personal.config.Message;
import com.src.xyzk_personal.config.ServerSocket;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Service;
import android.content.ContentValues;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


@SuppressLint("SimpleDateFormat")
public class EolNewFunctionActivity extends Activity {
    private static String TAG = "EolNewFunctionActivity";
    Context context = EolNewFunctionActivity.this;
    //锁定屏幕
    private PowerManager powerManager = null;
    private WakeLock wakeLock = null;
    //函数功能标题
    private TextView m_func_title = null;
    //功能选择
    //private int m_select_car = -1;
    //private int m_select_func = -1;
    //private String m_serialnum = null;
    //ListView列表
    private ListView m_listshow = null;
    private ArrayList<Map<String, String>> m_listshowArray = null;
    private ListShowAdapter m_listshow_adapter = null;
    private ArrayList<Map<String, String>> m_listshowhide = null; //隐藏的列表
    private List<EcuModule> modules = new ArrayList<>();
    EcuModule module = null;
    //提示文本
    private TextView m_showtip = null;
    private MsgWaitDialog waitdialog = null;

    private ThreadDiagnose m_thread = null; //执行线程
    private boolean m_threadstart = false;
    //private int id_num=100;
    boolean learnKey;
    String ems_calId = "";
    String ems_cvn = "";
    boolean m_upfile_isok = false;
    int m_fcm_fh = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.eolnewfunction_activity);
        //锁定屏幕初始化
        powerManager = (PowerManager) this.getSystemService(Service.POWER_SERVICE);
        wakeLock = this.powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");
        //是否需计算锁的数量
        wakeLock.setReferenceCounted(false);
        //获取Bundle消息
        Bundle bund = getIntent().getExtras();
        m_func_title = (TextView) findViewById(R.id.func_show_func);
        m_func_title.setText(bund.getString("TITLE"));
        //m_select_car = bund.getInt("CAR");
        //m_select_func = bund.getInt("FUNC");
        //列表初始化
        m_listshow = (ListView) findViewById(R.id.func_show_list);
        m_listshowArray = new ArrayList<Map<String, String>>();
        m_listshowhide = new ArrayList<Map<String, String>>();
        m_listshow_adapter = new ListShowAdapter(m_listshowArray);
        m_listshow.setAdapter(m_listshow_adapter);
        //提示信息框
        m_showtip = (TextView) findViewById(R.id.func_show_text);

        Common.cartype.Result = 0;
        //开始测试
        final String func_name = bund.getString("FUNC_NAME");
        final String func_file = bund.getString("DIR");
        if (func_name.equals("福瑞泰克FCM标定")) {
            final InputConfigDialog dialog = new InputConfigDialog(this);
            dialog.setTitle("请输入高度数据(如:327):");
            dialog.setOnOKButton(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    String data = dialog.GetEditString();
                    if ((data != null) && (data.length() > 0))
                        m_fcm_fh = Integer.valueOf(data);
                    if ((m_fcm_fh > 300) && (m_fcm_fh < 400)) //ok
                    {
                        dialog.dismiss();
                        StartDiagnose(func_file, func_name);
                    } else {
                        Toast.makeText(context, "输入错误,请重新输入.", Toast.LENGTH_SHORT).show();
                        dialog.setEditString("");
                        return;
                    }
                }
            });
            dialog.setOnCloseButton(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                    finish();
                }
            });
            dialog.show();
        } else
            StartDiagnose(bund.getString("DIR"), func_name);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //请求常亮
        wakeLock.acquire();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //取消屏幕常亮
        wakeLock.release();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:    //返回键
                if (m_threadstart == true) {
                    //最后提示
                    final MsgWaitDialog waitdialog = new MsgWaitDialog(EolNewFunctionActivity.this);
                    waitdialog.setText(getResources().getString(R.string.abort_current_diagnose_process) + "?");
                    waitdialog.setWaitTime(0);
                    waitdialog.ShowCancel();
                    waitdialog.show();
                    waitdialog.setOnOKButton(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            waitdialog.dismiss();
                            StopDiagnose();
                            finish();
                        }
                    });
                    return true;
                } else {
                    finish();
                }
            default:
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    //显示提示信息
    private void ShowFuncTip(String context) {
        m_handler.obtainMessage(Message.MSG_Func_ShowTip, context).sendToTarget();
    }

    private void ShowFuncTip(int Rid) {
        ShowFuncTip(getString(Rid));
    }

    private final Handler m_handler = new Handler() {
        @SuppressLint("HandlerLeak")
        @SuppressWarnings("unchecked")
        public void handleMessage(android.os.Message msg) {
            if (m_threadstart == false) return;
            switch (msg.what) {
                case Message.MSG_Dialog_WaitTime:
                    if (waitdialog != null) {
                        waitdialog.dismiss();
                        waitdialog = null;
                    }
                    waitdialog = new MsgWaitDialog(EolNewFunctionActivity.this);
                    waitdialog.setWaitTime(msg.arg1);
                    if (msg.arg2 == 1) //ON
                        waitdialog.setText(R.string.msg_show_keyon);
                    else if (msg.arg2 == 2) //OFF
                        waitdialog.setText(R.string.msg_show_keyoff);
                    else if (msg.arg2 == 3) //直接显示文本
                        waitdialog.setText((String) msg.obj);
                    else if (msg.arg2 == 4) //OFF
                        waitdialog.setText(R.string.msg_show_context6);
                    else if (msg.arg2 == 5) //OFF
                        waitdialog.setText(R.string.msg_show_context7);
                    else if (msg.arg2 == 6) //WAIT
                        waitdialog.setText(R.string.msg_show_context10);
                    else if (msg.arg2 == 7) //START
                        waitdialog.setText(R.string.msg_show_keystart);
                    else
                        waitdialog.setText((String) msg.obj);
                    waitdialog.show();
                    //Common.wait = false;
                    break;
                case Message.MSG_Dialog_WaitIimeAutoClose:
                    if (Common.Debug) Log.i(TAG, "Show AutoClose");
                    if (msg.arg1 >= 0) {
                        if (waitdialog != null) {
                            waitdialog.dismiss();
                            waitdialog = null;
                        }
                        waitdialog = new MsgWaitDialog(EolNewFunctionActivity.this);
                        waitdialog.setWaitTime(msg.arg1);
                    }
                    if (msg.arg2 == 1) //ON
                        waitdialog.setText(R.string.msg_show_context1);
                    else if (msg.arg2 == 2)
                        waitdialog.setText(R.string.msg_show_context2);
                    else if (msg.arg2 == 3)
                        waitdialog.setText(R.string.msg_show_context3);
                    else if (msg.arg2 == 4)
                        waitdialog.setText(R.string.msg_show_context4);
                    else if (msg.arg2 == 5)
                        waitdialog.setText(R.string.msg_show_context5);
                    else if (msg.arg2 == 6)
                        waitdialog.setText(R.string.msg_show_context9);
                    else if (msg.arg2 == 7)
                        waitdialog.setText(R.string.msg_show_context11);
                    else if (msg.arg2 == 8)
                        waitdialog.setText(R.string.msg_show_context12);
                    else if (msg.arg2 == 9)
                        waitdialog.setText(R.string.msg_show_context13);
                    else
                        waitdialog.setText((String) msg.obj);
                    if (msg.arg1 >= 0) {
                        waitdialog.show();
                        waitdialog.SetAutoClose();
                    }
                    break;
                case Message.MSG_Dialog_Show_Text: //显示提示信息
                    if (waitdialog != null) {
                        waitdialog.setText((String) msg.obj);
                    }
                    break;
                case Message.MSG_Dialog_close:
                    if (waitdialog != null) {
                        if (waitdialog.IsShowing())
                            waitdialog.dismiss();
                        Common.wait = false;
                    }
                    break;
                case Message.MSG_Start_Diagnose:
                    if (m_thread != null) {
                        //结束线程
                        if (Common.Debug) Log.i(TAG, "Close Thread");
                        m_thread.close();
                        try {
                            Thread.sleep(300); //延时
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        m_thread = null;
                    }
                    if (Common.Debug) Log.i(TAG, "Start Thread");
                    break;
                case Message.MSG_Initial_Module:
                    //清除列表
                    m_listshowArray.clear();
                    m_listshowhide.clear();
                    m_listshow_adapter.notifyDataSetChanged();
                    m_threadstart = true;
                    break;
                case Message.MSG_ShowArray:    //显示
                    m_listshowArray.add((HashMap<String, String>) msg.obj);
                    m_listshow_adapter.notifyDataSetChanged();
                    break;
                case Message.MSG_ShowArrayHide: //隐藏的列表
                    m_listshowhide.add((HashMap<String, String>) msg.obj);
                    break;
                case Message.MSG_Func_ShowTip:    //显示提示信息
                    m_showtip.setText((String) msg.obj);
                    break;
                case Message.MSG_Dialog_SHow_YESNO:  //显示提示信息对话框
                    final MsgWaitDialog waitdialog = new MsgWaitDialog(EolNewFunctionActivity.this);
                    waitdialog.setText((String) msg.obj);
                    waitdialog.setWaitTime(0);
                    waitdialog.ShowCancel();
                    if (learnKey) {//将确定取消变成是否
                        waitdialog.ShowYesOrNo();
                        learnKey = false;
                    }
                    waitdialog.setOnCancelButton(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Common.dialog_result = false;    //点击了取消
                            waitdialog.dismiss();
                            Common.wait = false;
                        }
                    });
                    waitdialog.setOnOKButton(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Common.dialog_result = true;    //点击了取消
                            waitdialog.dismiss();
                            Common.wait = false;
                        }
                    });
                    waitdialog.show();
                    break;
                case Message.MSG_Dialog_InputData:
                    final InputVinDialog datadialog = new InputVinDialog(EolNewFunctionActivity.this);
                    datadialog.setTitle((String) msg.obj);
                    datadialog.setOnOKButton(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            String pw = datadialog.GetEditString();
                            if (Common.password.equals(pw)) {
                                datadialog.dismiss();
                                inputEmsCalId();
                            } else {
                                Toast.makeText(EolNewFunctionActivity.this, getResources().getString(R.string.enter_password_error), 0).show();
                                datadialog.setEditString("");
                                return;
                            }
                        }
                    });
                    datadialog.show();
                default:
                    break;
            }
        }

        ;
    };
    //钥匙数量
    public int key_number;

    private void inputEmsCalId() {
        final InputVinDialog datadialog = new InputVinDialog(EolNewFunctionActivity.this);
        datadialog.setTitle("请输入EMS CALID");
        datadialog.setOnOKButton(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ems_calId = datadialog.GetEditString();
                datadialog.dismiss();
                inputEmsVcn();
            }
        });
        datadialog.show();
    }

    private void inputEmsVcn() {
        final InputVinDialog datadialog = new InputVinDialog(EolNewFunctionActivity.this);
        datadialog.setTitle("请输入EMS VCN");
        datadialog.setOnOKButton(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ems_cvn = datadialog.GetEditString();
                datadialog.dismiss();
                Common.wait = false;
            }
        });
        datadialog.show();
    }

    public class ListShowAdapter extends BaseAdapter {
        private ArrayList<Map<String, String>> listdata = null;
        private FuncListShow listshow = null;
        private View view = null;
        private LayoutInflater inflater = null;
        private int Selected = -1;

        public ListShowAdapter(ArrayList<Map<String, String>> Pdata) {
            listdata = Pdata;
        }

        @Override
        public int getCount() {
            if (listdata != null)
                return listdata.size();
            else
                return 0;
        }

        @Override
        public Object getItem(int position) {
            if (listdata != null && listdata.size() > position)
                return listdata.get(position);
            else
                return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        public void setSelected(int pos) {
            Selected = pos;
        }

        public int getSelected() {
            return Selected;
        }

        @SuppressLint({"ViewHolder", "InflateParams"})
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.eolnewfunction_showlistitem, null, false);
            listshow = (FuncListShow) view.getTag();
            if (listshow == null) {
                listshow = new FuncListShow();
                listshow.id = (TextView) view.findViewById(R.id.eolnewfunction_listshow_id);
                listshow.context = (TextView) view.findViewById(R.id.eolnewfunction_listshow_context);
                listshow.result = (TextView) view.findViewById(R.id.eolnewfunction_listshow_result);
                listshow.time = (TextView) view.findViewById(R.id.eolnewfunction_listshow_time);
                view.setTag(listshow);
            }
            if (listdata.get(position).get("SHOW_TIME").equals("N.OK")) {
                view.setBackgroundColor(Color.RED);
            } else if (position == Selected) {
                //listlayout.text.setBackgroundColor(Color.GREEN);
                view.setBackgroundColor(Color.GREEN);
                listshow.id.setSelected(true);
                listshow.id.setPressed(true);
            } else if (position % 2 == 1) {
                listshow.id.setSelected(false);
                listshow.id.setPressed(false);
                view.setBackgroundColor(0xFFC0C0C0);
            } else {
                listshow.id.setSelected(false);
                listshow.id.setPressed(false);
                view.setBackgroundColor(Color.WHITE);
            }
            listshow.id.setText(listdata.get(position).get("SHOW_ID"));
            listshow.context.setText(listdata.get(position).get("SHOW_CONTEXT"));
            listshow.result.setText(listdata.get(position).get("SHOW_RESULT"));
            listshow.time.setText(listdata.get(position).get("SHOW_TIME"));
            return view;
        }
    }

    class FuncListShow {
        TextView id;
        TextView context;
        TextView result;
        TextView time;
    }
    //--------------------------------车型相关诊断--------------------------------------------

    //启动线程
    public void StartDiagnose(String Pstep, String Pfunc) {
        //启动线程
        m_thread = new ThreadDiagnose(Pstep, Pfunc);
        if (Common.Debug) Log.i(TAG, "启动线程...");
        m_threadstart = true;
        m_thread.start();
    }

    //结束线程
    private void StopDiagnose() {
        if (m_thread != null) {
            Common.wait = false;
            //结束线程
            if (Common.Debug) Log.i(TAG, "Close Thread");
            m_thread.close();
            try {
                Thread.sleep(500); //延时
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            m_thread = null;
            m_threadstart = false;
        }
    }

    //-----------------------执行线程-------------------------------
    public class ThreadDiagnose extends Thread {
        String stepname = null;    //执行的函数名称
        String func = null;    //执行功能
        ArrayList<String> t_print = new ArrayList<String>();
        ArrayList<String> t_printtemp = null;
        ArrayList<String> t_downline = new ArrayList<String>();
        int showId = 0;
        ArrayList<HashMap<String, String>> updateData = new ArrayList<HashMap<String, String>>();
        boolean t_isok = true;
        String t_dtc = "";    //打印DTC缓存区
        String vcuReadVin;
        ArrayList<String> clearOrReadDtc = new ArrayList<String>();
        boolean readVin;
        //初始化连接service//蓝牙服务
        //BluetoothAdapterService m_com = BluetoothAdapterService.getInstance();
        //m_communication m_com = m_communication.getInstance();
        Communication m_com = Communication.getInstance();
        boolean t_havedtc = false;    //系统是否存在故障码
        public boolean exit = false;

        public ThreadDiagnose(String Pstep, String Pfunc) {
            stepname = Pstep;
            func = Pfunc;
        }

        @Override
        public void run() {
            if (exit == true) return;
            if (Common.Debug) Log.i(TAG, "连接接头...");
            if (Common.Flash == true) //刷写
            {
                String ver = m_com.ReadBoxVersion();
                if (ver.length() > 4) //ok
                {
                    Common.BoxName = ver.substring(0, 12);
                    String app = ver.substring(ver.length() - 4);
                    ShowFuncTip("Box序列号:" + Common.BoxName + "\nBox版本号:V" + app);
                } else {
                    ShowFuncTip("通讯盒初始化失败,请检查车辆是否已经连接!");
                    return;
                }
            } else {
                Sleep(100);
                if (ConnectToBox() != 0) return;
            }
            //执行功能模块
            //初始化清除列表
            m_handler.obtainMessage(Message.MSG_Initial_Module).sendToTarget();
            Sleep(50);
            if (Common.cartype.OptMode == 0) {
                //ShowProcessList("---", "---","开始检测...",  Common.Rnull);
                SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //日期格式
                Common.cartype.start_time = sDateFormat.format(new java.util.Date());  //当前时间
                AutoFunction();
                Common.cartype.end_time = sDateFormat.format(new java.util.Date());  //当前时间
            } else {
                if (stepname != null) {
                    SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //日期格式
                    Common.cartype.start_time = sDateFormat.format(new java.util.Date());  //当前时间
                    if (!TextUtils.isEmpty(func)) {
                        ManuFunction(func);
                    }
                    Common.cartype.end_time = sDateFormat.format(new java.util.Date());  //当前时间
                }
            }
            close();
            ShowFuncTip(R.string.func_show_saveresult);
            //存储结果
            if (modules.size() > 0) {
                Common.cartype.Result = 1;
                for (EcuModule mod : modules) {
                    if (mod.getresult() > 1) {
                        Common.cartype.Result = mod.getresult();
                        break;
                    }
                }
            }
            // todo 上传服务器并保存至数据库
            SendAddResult(m_func_title.getText().toString(), m_listshowArray);
            //根据上传数据将其存储进数据库中
            SaveDataToDb(m_listshowArray);

            Sleep(100);
            ShowFuncTip(R.string.func_show_tip_exit);
            Sleep(100);
            m_threadstart = false;
            super.run();
        }

        void close() {
            exit = true;
            //m_com.close();
        }

        private boolean SendAddResult(String Pname, List<Map<String, String>> listData) {
            String v_print = "";
            //上传web服务器
            JSONObject jsonmain = new JSONObject();
            try {
                jsonmain.put("resultVin", new String(Common.cartype.vin));
                jsonmain.put("resultCar", Common.cartype.cartype);
                jsonmain.put("resultCartype", Common.cartype.cartype);
                jsonmain.put("resultStation", Pname);
                jsonmain.put("resultCarname", Common.cartype.name);
                //jsonmain.put("resultCardate",Common.cartype.date);
                jsonmain.put("resultCardate", Common.cartype.start_time);
                jsonmain.put("resultCartime", Common.cartype.start_time);
                jsonmain.put("resultDevice", Common.BoxName);
                //打印机编号做返修不打印的特殊处理
                if (Common.cartype.OptMode == 0) {
                    jsonmain.put("resultPrintnum", "" + Common.Printnum);
                } else {
                    jsonmain.put("resultPrintnum", "99");
                }
                jsonmain.put("resultTestnum", "1");
                if (Common.cartype.Result <= 1)
                    jsonmain.put("resultResult", "OK");
                else
                    jsonmain.put("resultResult", "NG");
                //int v_size = modules.size();
                for (EcuModule mod : modules) {
                    v_print += mod.toString();
                }

                jsonmain.put("resultPrint", v_print);
                jsonmain.put("resultPin", Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
                jsonmain.put("resultEsk", " ");
                jsonmain.put("resultColor", Common.cartype.name);
                jsonmain.put("resultAppver", getString(R.string.Version));
                jsonmain.put("resultUp2mes", "0");
                jsonmain.put("resultUser", "test");
                jsonmain.put("fileName", m_com.GetLogfileName());
                jsonmain.put("resultLog", "");
                JSONArray array = new JSONArray();
                for (int k = 0; k < listData.size(); k++) {
                    JSONObject jsondetail = new JSONObject();
                    jsondetail.put("mVin", new String(Common.cartype.vin));
                    jsondetail.put("mTestcode", listData.get(k).get("SHOW_ID"));
                    jsondetail.put("mContext", listData.get(k).get("SHOW_CONTEXT"));
                    jsondetail.put("mTestdata", listData.get(k).get("SHOW_RESULT"));
                    jsondetail.put("mStand", listData.get(k).get("SHOW_CTAND"));
                    jsondetail.put("mResult", listData.get(k).get("SHOW_TIME"));
                    array.put(k, jsondetail);
                }
                jsonmain.put("tableResultDetails", array);
            } catch (Exception e) {
                e.printStackTrace();
                m_com.m_log.PrintLog("Error:" + e.toString());
            }
            Long v_upfileid = (long) 0;

            // 上传
            m_com.m_log.PrintLog("UpAddr:" + Common.web_updata);
            m_com.m_log.PrintLog(jsonmain.toString());
            String res = HttpRequest.sendPostToMyMes(Common.web_updata, jsonmain.toString().replace(">", ""));
            m_com.m_log.PrintLog(res);
            if (res.indexOf("200") > 0) //ok
            {
                try {
                    JSONObject resjson = new JSONObject(res);
                    JSONObject son = resjson.getJSONObject("data");
                    if (son != null)
                        v_upfileid = son.getLong("resultId");
                    ShowFuncTip(getResources().getString(R.string.uploaded_server_data_success));
                    Common.updata_isok = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Common.updata_isok = false;
            }
            //上传日志文件
            if (v_upfileid > 0) {
                ShowFuncTip(getResources().getString(R.string.uploading_log_file));
                m_com.m_log.PrintLog(Common.web_API_File + ":" + m_com.getFilePaths());
                if (uploadFiles(Common.web_API_File, m_com.getFilePaths(), v_upfileid) == true)
                    ShowFuncTip(getResources().getString(R.string.log_file_uploaded_success));
                else
                    ShowFuncTip(getResources().getString(R.string.log_file_uploaded_success));
            }
            return true;
        }

        /**
         * 文件上传线程
         *
         * @param uploadUrl
         * @param filePaths
         * @param id
         */
        public boolean uploadFiles(String uploadUrl, String filePaths, Long id) {
            m_upfile_isok = false;
            MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
            String fname = filePaths;
            File tempfile = new File(fname);
            //根据文件的后缀名，获得文件类型
            builder.setType(MultipartBody.FORM)
                    .addFormDataPart("resultId", String.valueOf(id))// 其他参数信息
                    .addFormDataPart( //给Builder添加上传的文件
                            "files",  //请求的名字
                            tempfile.getName(), //文件的文字，服务器端用来解析的
                            RequestBody.create(MediaType.parse("multipart/form-data"), tempfile)//创建RequestBody，把上传的文件放入
                    );
            MultipartBody requestBody = builder.build();
            Request request = new Request.Builder()
                    .url(uploadUrl)
                    .post(requestBody)
                    .build();
            OkHttpClient client = new OkHttpClient.Builder()
                    .connectTimeout(10000, TimeUnit.SECONDS)
                    .readTimeout(10000, TimeUnit.SECONDS)
                    .writeTimeout(10000, TimeUnit.SECONDS).build();
            client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Call call, final IOException e) {
                    Log.e("TAG", "返回内容===失败>:" + e.toString());
                    m_com.m_log.PrintLog(e.toString());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    String result = response.body().string();
                    Log.e("TAG", "返回内容===成功>:" + result);
                    m_com.m_log.PrintLog(result);
                    m_upfile_isok = true;
                }
            });
            return m_upfile_isok;
        }

        void SaveDataToDb(ArrayList<Map<String, String>> list) {
            String v_print = "";
            for (EcuModule mod : modules) {
                v_print += mod.toString();
            }
            DbAdapter db = new DbAdapter(context);
            //---------------------第一步存主数据库---------------------
            db.open();
            //查询测试次数
            int oldtestnum = db.QueryMainTestNum(new String(Common.cartype.vin));
            if (Common.Debug) Log.i(TAG, "已经存储次数为:" + oldtestnum);
            ContentValues cv = new ContentValues();
            cv.put(TableMain.car, Common.cartype.carmode_dir);
            cv.put(TableMain.config, Common.cartype.config);
            cv.put(TableMain.esk, Commonfunc.bytesToHexStringP(Common.cartype.esk, 0, 16));
            cv.put(TableMain.vin, new String(Common.cartype.vin));
            cv.put(TableMain.pin, Commonfunc.bytesToHexStringP(Common.cartype.pin, 2, 4));
            cv.put(TableMain.cartype, Common.cartype.cartype);
            cv.put(TableMain.carcolor, Common.cartype.name);
            cv.put(TableMain.station, m_func_title.getText().toString());
            cv.put(TableMain.carname, Common.cartype.name);
            cv.put(TableMain.timestart, Common.cartype.start_time);
            cv.put(TableMain.timeend, Common.cartype.end_time);
            cv.put(TableMain.printdata, v_print);
            cv.put(TableMain.device, Common.cartype.box_serialnum);
            cv.put(TableMain.appversion, getString(R.string.Version));
            cv.put(TableMain.testnum, oldtestnum + 1);
            cv.put(TableMain.logfileName, m_com.GetLogfileName());
            cv.put(TableMain.logpath, m_com.getFilePaths());
            if (Common.cartype.Result <= 1)
                cv.put(TableMain.result, "OK");
            else
                cv.put(TableMain.result, "NG");
            if (Common.Debug) Log.i(TAG, cv.toString());
            db.addmainTable(cv, Common.updata_isok);
            //---------------------第二步，存储详细数据---------------------
            int datanum = db.CreateTableData(new String(Common.cartype.vin));
            db.StartAddMost();
            if (Common.Debug) Log.i(TAG, "查询到的测试次数:" + datanum);
            if (list != null) {
                for (int i = 0; i < list.size(); i++) {
                    ContentValues cdata = new ContentValues();
                    cdata.put(TableData.testnum, oldtestnum + 1);
                    cdata.put(TableData.testcode, list.get(i).get("SHOW_ID"));
                    cdata.put(TableData.context, list.get(i).get("SHOW_CONTEXT"));
                    cdata.put(TableData.testdata, list.get(i).get("SHOW_RESULT"));
                    cdata.put(TableData.teststand, list.get(i).get("SHOW_CTAND"));
                    cdata.put(TableData.result, list.get(i).get("SHOW_TIME"));
                    //if(Common.Debug) Log.i(TAG,cv.toString());
                    db.addDatatotable(new String(Common.cartype.vin), cdata, false);
                }
            }
            db.StopAddMost();
            db.close();
            //m_handler.obtainMessage(MSG_Connect_MainSQL, cv).sendToTarget();
        }

        void SaveDataToDb(String printdata, ArrayList<Map<String, String>> list) {
            DbAdapter db = new DbAdapter(context);
            //---------------------第一步存主数据库---------------------
            db.open();
            //查询测试次数
            int oldtestnum = db.QueryMainTestNum(new String(Common.cartype.vin));
            if (Common.Debug) Log.i(TAG, "已经存储次数为:" + oldtestnum);
            ContentValues cv = new ContentValues();
            cv.put(TableMain.vin, new String(Common.cartype.vin));
            cv.put(TableMain.cartype, Common.cartype.cartype);
            cv.put(TableMain.config, Common.cartype.config);
            cv.put(TableMain.carname, Common.cartype.name);
            cv.put(TableMain.timestart, Common.cartype.start_time);
            cv.put(TableMain.timeend, Common.cartype.end_time);
            if (Common.cartype.Result <= 1)
                cv.put(TableMain.result, "OK");
            else
                cv.put(TableMain.result, "N.OK");
            cv.put(TableMain.printdata, printdata);
            cv.put(TableMain.device, Common.cartype.box_serialnum);
            cv.put(TableMain.testnum, oldtestnum + 1);
            if (Common.Debug) Log.i(TAG, cv.toString());
            db.addmainTable(cv, false);
            //---------------------第二步，存储详细数据---------------------
            int datanum = db.CreateTableData(new String(Common.cartype.vin));
            db.StartAddMost();
            if (Common.Debug) Log.i(TAG, "查询到的测试次数:" + datanum);
            if (list != null) {
                for (int i = 0; i < list.size(); i++) {
                    ContentValues cdata = new ContentValues();
                    cdata.put(TableData.testnum, oldtestnum + 1);
                    cdata.put(TableData.testcode, list.get(i).get("SHOW_ID"));
                    cdata.put(TableData.context, list.get(i).get("SHOW_CONTEXT"));
                    cdata.put(TableData.testdata, list.get(i).get("SHOW_RESULT"));
                    cdata.put(TableData.result, list.get(i).get("SHOW_TIME"));
                    db.addDatatotable(new String(Common.cartype.vin), cdata, false);
                }
            }
            //加入隐藏list
            if (m_listshowhide != null) {
                for (int i = 0; i < m_listshowhide.size(); i++) {
                    ContentValues cdata = new ContentValues();
                    cdata.put(TableData.testnum, oldtestnum + 1);
                    cdata.put(TableData.testcode, m_listshowhide.get(i).get("SHOW_ID"));
                    cdata.put(TableData.context, m_listshowhide.get(i).get("SHOW_CONTEXT"));
                    cdata.put(TableData.testdata, m_listshowhide.get(i).get("SHOW_RESULT"));
                    cdata.put(TableData.result, m_listshowhide.get(i).get("SHOW_TIME"));
                    //if(Common.Debug) Log.i(TAG,cv.toString());
                    db.addDatatotable(new String(Common.cartype.vin), cdata, false);
                }
            }
            db.StopAddMost();
            db.close();
            //m_handler.obtainMessage(MSG_Connect_MainSQL, cv).sendToTarget();
        }

        //自动执行
        private void AutoFunction() {
            //获取step数据
            Ini inistep;
            try {
                inistep = new Ini(new File(stepname));
                Profile.Section sec = inistep.get("STEP");
                int num = Integer.parseInt(sec.get("NUM"));
                for (int i = 0; i < num; i++) {
                    if (exit) return;
                    Sleep(Common.waittime);
                    //判断OPT可选,过滤SHW项目,直接显示REQ项目
                    String step_name = sec.get("T" + i);
                    String v_mode = step_name.substring(0, 3);
                    String v_name = step_name.substring(4);
                    if (Common.Debug)
                        Log.i(TAG, "v_mode = " + v_mode + "; v_name = " + v_name + "; i = " + i);
                    switch (v_mode) {
                        case "OPT":
                        //处理可选项目
                        {
                            int mode_num = Common.cartype.getMap(v_name);
                            if (mode_num > 0) {
                                module = new EcuModule(v_name, context);
                                //执行单个模块
                                ExecutionModule(inistep, v_name + mode_num);
                                modules.add(module);
                            }
                            break;
                        }
                        case "REQ":
                        //处理比选项目
                        {
                            //执行单个模块
                            int mode_num = Common.cartype.getMap(v_name);
                            module = new EcuModule(v_name, context);
                            if (Common.cartype.carmode_dir.equals("CX62"))
                                ExecutionModule(inistep, v_name + mode_num);
                            else
                                ExecutionModule(inistep, v_name);
                            modules.add(module);
                            break;
                        }
                        case "SHW":
                        //处理弹出显示窗口

                            int v_add1 = step_name.indexOf("<");
                            int v_add2 = step_name.indexOf(">");
                            if (Common.Debug)
                                Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                            String v_data1 = step_name.substring(4, v_add1);
                            int v_time = Integer.valueOf(step_name.substring(v_add1 + 1, v_add2));
                            if (v_data1.equals("ON") == true) {
                                Common.wait = true;
                                m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 1).sendToTarget();
                                while (Common.wait) {
                                    Sleep(Common.waittime);
                                }
                                ;
                            } else if (v_data1.equals("OFF") == true) {
                                Common.wait = true;
                                m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 2).sendToTarget();
                                while (Common.wait) {
                                    Sleep(Common.waittime);
                                }
                                ;
                            } else if (v_data1.equals("START") == true) {
                                Common.wait = true;
                                m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 7).sendToTarget();
                                while (Common.wait) {
                                    Sleep(Common.waittime);
                                }
                                ;
                            } else if (v_data1.equals("WAIT") == true) {
                                Common.wait = true;
                                m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 6).sendToTarget();
                                while (Common.wait) {
                                    Sleep(Common.waittime);
                                }
                                ;
                            }
                            break;
                    }
                }
            } catch (InvalidFileFormatException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }

        //手动执行
        private void ManuFunction(String name) {
            //获取step数据
            Ini inistep;
            inistep = Common.cartype.istep;
            if (inistep == null) return;
            //----------------------------------------------
            //根据用户选择执行
            //清除列表
            m_handler.obtainMessage(Message.MSG_Initial_Module).sendToTarget();
            //特殊处理名称问题
            if (Common.Debug) Log.i(TAG, "v_name = " + name);
            //执行单个模块
            if (Common.cartype.carmode_dir.equals("CX62"))
                ExecutionModule(inistep, name + Common.cartype.getMap(name));
            else {
                if (Common.cartype.getMap(name) > 0)
                    ExecutionModule(inistep, name + Common.cartype.getMap(name));
                else
                    ExecutionModule(inistep, name);
            }
        }

        //执行单个模块功能
        private void ExecutionModule(Ini file, String modename) {
            //显示模块名称
            Profile.Section sec = null;
            sec = file.get(modename); //获取模块内容
            if (sec == null) {
                ShowProcessList(0, "Parsing files", modename, Common.Rnok);
                return;
            }
            //显示检测内容
            String v_show = "";
            if (Common.cartype.getMap("AUTO") > 0)
                v_show = m_func_title.getText().toString() + "->" + modename + "...";
            else
                v_show = m_func_title.getText().toString() + "...";
            ShowFuncTip(getResources().getString(R.string.implement) + ":" + v_show);
            m_com.m_log.PrintAppend(3, v_show);
            //第一步 显示模块标题
            t_isok = true; //复位
            t_dtc = "";
            //显示
            ShowProcessList(sec.get("MODULE_ID"), sec.get("MODULE_NAME"), "---", Common.Rnull);
            //第二步，开始执行单个具体模块
            if (Common.cartype.carmode_dir.equals("CX62")) {
                if (modename.equals("PEPS1")) {
                    fun_CX62_PEPS1(sec);
                } else if (modename.equals("BCM1")) {
                    fun_CX62_BCM1(sec);

                } else if (modename.equals("BCM2")) {
                    fun_CX62_BCM2(sec);
                } else if (modename.equals("ICM1")) {
                    fun_CX62_ICM1(sec);
                } else if (modename.equals("RRM1")) {
                    fun_CX62_RRM1(sec);
                } else if (modename.equals("TBOX1")) {
                    fun_CX62_TBOX1(sec);
                } else if (modename.equals("RADAR1")) {
                    fun_CX62_RADAR1(sec);
                } else if (modename.equals("EPB1")) {
                    fun_CX62_EPB1(sec);
                } else if (modename.equals("EMS1")) {
                    fun_CX62_EMS1(sec);
                } else if (modename.equals("APM2") || modename.equals("APM1")) {
                    fun_CX62_APM2(sec);
                } else if (modename.equals("EPS1")) {
                    fun_CX62_EPS1(sec);
                } else if (modename.equals("ABS1")) {
                    fun_CX62_ABS1(sec);
                } else if (modename.equals("ESP1")) {
                    fun_CX62_ESP1(sec);
                } else if (modename.equals("SAM1")) {
                    fun_CX62_SAM1(sec);
                } else if (modename.equals("BM1")) {
                    fun_CX62_BM1(sec);
                } else if (modename.equals("FCW1")) {
                    fun_CX62_FCW1(sec);//TODO
                } else if (modename.equals("EPB标定1")) {
                    fun_CX62_EPB_BiaoDing1(sec);
                } else if (modename.equals("ESP标定1")) {
                    fun_CX62_ESP_BiaoDing1(sec);
                } else if (modename.equals("ESP写加注字节0")) {
                    fun_CX62_ESP_JiaZhu1(sec);
                } else if (modename.equals("手环学习1")) {
                    fun_CX62_keylearn1(sec);
                } else if (modename.equals("ClearAllDtc0")) {
                    fun_CX62_ClearDtc(sec);
                } else if (modename.equals("ReadAllDtc0")) {
                    fun_CX62_ReadDtc(sec);
                } else if (modename.equals("ReadConfig0")) {
                    fun_CX62_ReadConfig(sec);
                } else if (modename.equals("OBD检查0")) {
                    fun_CX62_OBD_check(sec);
                } else if (modename.equals("EMS刷写前0")) {
                    fun_CX62_FlashFront(sec);
                } else if (modename.contains("EMS刷写")) {
                    fun_CX62_Flash(sec, modename);
                } else if (modename.equals("OBD上传(MT)0")) {
//					fun_CX62_OBD_upload(false);
                } else if (modename.equals("OBD上传(DCT)0")) {
//					fun_CX62_OBD_upload(true);
                }
            } else if (Common.cartype.carmode_dir.equals("CX62B")) {
                if (modename.equals("IMMO1")) {
                    fun_CX62B_IMMO1(sec);
                } else if (modename.equals("EMS1")) {
                    fun_CX62B_EMS1(sec);
                } else if (modename.equals("ESP1")) {
                    fun_CX62B_ESP1(sec);
                } else if (modename.equals("EPS1") || modename.equals("ICM1") || modename.equals("PLG1") ||
                        modename.equals("CGW1") || modename.equals("FIPM1") || modename.equals("RADAR1") || modename.equals("EPB1")) //config
                {
                    fun_CX62B_standconfig1(sec);
                } else if (modename.equals("FCM1") || modename.equals("FRM1") || modename.equals("DVR1") ||
                        modename.equals("FWS1") || modename.equals("GSM1") || modename.equals("ABM1")) //vin
                {
                    fun_CX62B_standVIN1(sec);
                } else if (modename.equals("RRM1") || modename.equals("TBOX1") || modename.equals("RRM2")) //vin and config
                {
                    fun_CX62B_standVINAndConfig1(sec);
                } else if (modename.equals("APM1")) {
                    fun_CX62B_APM1(sec);
                } else if (modename.equals("BM1")) {
                    fun_CX62B_BM1(sec);
                } else if (modename.equals("SEAT1")) {
                    fun_CX62B_SEAT1_Cal(sec);
                } else if (modename.equals("7DCT1") || modename.equals("DCT1") || modename.equals("DCT2")) {
                    fun_CX62B_TCU1(sec);
                } else if (modename.equals("TPMS1")) {
                    fun_JT_Stand1(sec);
                } else if (modename.equals("EPS标定1")) {
                    fun_CX62B_EPS1_Cal(sec);
                } else if (modename.equals("EPB标定1")) {
                    fun_CX62B_EPB1_Cal(sec);
                } else if (modename.equals("ESP标定1")) {
                    fun_CX62B_ESP1_Cal(sec);
                } else if (modename.equals("SAM标定1")) {
                    fun_CX62B_SAM1_Cal(sec);
                } else if (modename.equals("GBC1")) {
                    fun_CX62B_GBC1_Cal(sec);
                } else if (modename.equals("ClearAllDTC")) {
                    fun_CX62B_ClearAllDtc(sec);
                } else if (modename.equals("ReadAllDTC")) {
                    fun_CX62B_ReadAllDtc(sec);
                } else if (modename.equals("ReadConfig")) {
                    fun_CX62B_ReadConfig(sec);
                } else if (modename.equals("ReadInfo")) {
                    fun_CX62B_ReadVerInfo(sec);
                } else if (modename.equals("ESP写加注字节")) {
                    fun_CX62_ESP_JiaZhu1(sec);
                } else if (modename.equals("手环学习1")) {
                    fun_CX62_keylearn1(sec);
                } else if (modename.equals("OBD检查")) {
                    fun_CX62_OBD_check(sec);
                } else if (modename.equals("EMS刷写前")) {
                    fun_CX62_FlashFront(sec);
                } else if (modename.equals("OBD上传(MT)")) {
//					fun_CX62_OBD_upload(false);
                } else if (modename.equals("OBD上传(DCT)")) {
//					fun_CX62_OBD_upload(true);
                } else if (modename.equals("福瑞泰克FCM标定1")) {
                    fun_CX62B_FCM2_Cal(sec);
                } else if (modename.equals("TCU刷写1")) {
                    fun_JX65_TcuFlash1(sec, "TCU1");
                } else if (modename.equals("FRM刷写1")) {
                    fun_JX65_FrmFlash1(sec, "FRM1");
                } else if (modename.equals("FCM刷写1")) {
                    fun_JX65_FcmFlash1(sec, "FCM1");
                } else if (modename.equals("EMS刷写1")) {
                    fun_JX65_Ems1781(sec, "EMS1");
                } else if (modename.equals("EMS刷写2")) {
                    fun_JX65_Ems1788(sec, "EMS2");
                }
            } else if (Common.cartype.carmode_dir.equals("JX65")) {
                if (modename.equals("Version") || modename.equals("ClearDTC") || modename.equals("ReadDTC") || modename.equals("ReadInfo") || modename.equals("ReadConfig"))
                    fun_JT_Stand2(sec);
                else if (modename.equals("IMMO1")) {
                    if (Common.cartype.carmode_dir.equals("JX65"))
                        fun_JX65_IMMO1(sec);
                    else
                        fun_JX65PHEV_IMMO1(sec);
                } else if (modename.equals("SEAT1")) {
                    fun_CX62B_SEAT1_Cal(sec);
                } else if (modename.equals("7DCT1") || modename.equals("DCT1") || modename.equals("DCT2")) {
                    fun_CX62B_TCU1(sec);
                } else if (modename.equals("GBC1")) {
                    fun_JX65_GBC1_Cal(sec);
                } else if (modename.equals("EPS标定1")) {
                    fun_CX62B_EPS1_Cal(sec);
                } else if (modename.equals("EPB标定1")) {
                    fun_CX62B_EPB1_Cal(sec);
                } else if (modename.equals("ESP标定1")) {
                    fun_CX62B_ESP1_Cal(sec);
                } else if (modename.equals("ABM标定1")) {
                    fun_JX65_ABM_Cal(sec);
                } else if (modename.equals("SAM标定1")) {
                    fun_CX62B_SAM1_Cal(sec);
                } else if (modename.equals("OBD检查")) {
                    fun_CX62_OBD_check(sec);
                } else if (modename.equals("钥匙学习")) {
                    fun_JX65_IMMO_Addkey(sec);
                } else if (modename.equals("IMMO学习EMS")) {
                    fun_JX65_IMMO_studyems(sec);
                } else if (modename.equals("IMMO学习HCU")) {
                    fun_JX65PHEV_IMMO_studyHCU(sec);
                } else if (modename.equals("TCU刷写1")) //在这里判定是否有B点刷写
                {
                    if (fun_JX65_TcuFlash1(sec, "TCU1") == 3) {
                        //B点刷写
                        sec = file.get("TCU刷写3"); //获取模块内容
                        fun_JX65_TcuFlash3(sec, "TCU1");
                    }
                } else if (modename.equals("TCU刷写2")) {
                    fun_JX65_TcuFlash2(sec, "TCU1");
                } else if (modename.equals("FRM刷写1")) {
                    fun_JX65_FrmFlash1(sec, "FRM1");
                } else if (modename.equals("FCM刷写1")) {
                    fun_JX65_FcmFlash1(sec, "FCM1");
                } else if (modename.equals("EMS刷写1")) {
                    fun_JX65_Ems1781(sec, "EMS1");
                } else if (modename.equals("EMS刷写2")) {
                    fun_JX65_EmsUP8(sec, "EMS1");
                } else if (modename.equals("EMS刷写3")) {
                    fun_JX65_EmsUD8(sec, "EMS1");
                } else
                    fun_JT_Stand1(sec);
            } else if (Common.cartype.carmode_dir.equals("JX65PHEV")) {
                if (modename.equals("Version") || modename.equals("ClearDTC") || modename.equals("ReadDTC") || modename.equals("ReadInfo") || modename.equals("ReadConfig"))
                    fun_JT_Stand2(sec);
                else if (modename.equals("IMMO1")) {
                    if (Common.cartype.carmode_dir.equals("JX65"))
                        fun_JX65_IMMO1(sec);
                    else
                        fun_JX65PHEV_IMMO1(sec);
                } else if (modename.equals("SEAT1")) {
                    fun_CX62B_SEAT1_Cal(sec);
                } else if (modename.equals("7DCT1") || modename.equals("DCT1") || modename.equals("DCT2")) {
                    fun_CX62B_TCU1(sec);
                } else if (modename.equals("GBC1")) {
                    fun_JX65_GBC1_Cal(sec);
                } else if (modename.equals("EPS标定1")) {
                    fun_CX62B_EPS1_Cal(sec);
                } else if (modename.equals("EPB标定1")) {
                    fun_CX62B_EPB1_Cal(sec);
                } else if (modename.equals("ESP标定1")) {
                    fun_CX62B_ESP1_Cal(sec);
                } else if (modename.equals("ABM标定1")) {
                    fun_JX65_ABM_Cal(sec);
                } else if (modename.equals("SAM标定1")) {
                    fun_CX62B_SAM1_Cal(sec);
                } else if (modename.equals("OBD检查")) {
                    fun_CX62_OBD_check(sec);
                } else if (modename.equals("钥匙学习")) {
                    fun_JX65_IMMO_Addkey(sec);
                } else if (modename.equals("IMMO学习EMS")) {
                    fun_JX65_IMMO_studyems(sec);
                } else if (modename.equals("IMMO学习HCU")) {
                    fun_JX65PHEV_IMMO_studyHCU(sec);
                } else if (modename.equals("TCU刷写1")) {
                    fun_JX65PHEV_TcuFlash3(sec, "TCU1");
                } else if (modename.equals("FRM刷写1")) {
                    fun_JX65_FrmFlash1(sec, "FRM1");
                } else if (modename.equals("FCM刷写1")) {
                    fun_JX65PHEV_FcmFlash1(sec, "FCM1");
                } else if (modename.equals("EMS刷写1")) {
                    fun_JX65PHEV_Ems3(sec, "EMS1");
                } else
                    fun_JT_Stand1(sec);
            }
            if (t_isok) {
                t_print.add(sec.get("MODULE_NAME") + " - 合格");
            } else {
                t_print.add(sec.get("MODULE_NAME") + " -- 不合格");
            }
            if (t_printtemp != null) {
                for (int j = 0; j < t_printtemp.size(); j++) {
                    t_print.add(t_printtemp.get(j));
                    if (module != null) {
                        module.addcontext(t_printtemp.get(j));
                    }
                }
                t_printtemp.clear();
                t_printtemp = null;
            }
            if (modename.equals("ReadAllDtc0") || modename.equals("ClearAllDtc0")) {
                if (clearOrReadDtc.size() > 0) {
                    for (int i = 0; i < clearOrReadDtc.size(); i++) {
                        t_print.add(clearOrReadDtc.get(i));
                    }
                }
                clearOrReadDtc.clear();
            }
            ;
        }

        //显示一行数据
        //@SuppressLint("SimpleDateFormat")
        //isok: 0--"---";1--"OK";2--"N.OK"
        private void ShowProcessList(String id, String content, String result, int isok) {
            //SimpleDateFormat  sDateFormat   =   new   SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //日期格式
            //String date = sDateFormat.format(new java.util.Date());  //当前时间
            HashMap<String, String> map = new HashMap<String, String>();
            //id_num++;
            map.put("SHOW_ID", id);
            map.put("SHOW_CONTEXT", content);
            byte[] a = {0x00};
            byte[] b = {(byte) 0xFF};//用""替换乱码
            if (result.contains(new String(a))) {
                result = result.replace(new String(a), "");
            }
            if (result.contains(new String(b))) {
                result = result.replace(new String(b), "");
            }
            //解析一下测试值
            String v_stand = "";
            if (result != null) {
                if (result.indexOf("[") > 0) {
                    v_stand = result.substring(result.indexOf("[") + 1, result.length() - 1);
                    result = result.substring(0, result.indexOf("["));
                }
            }
            map.put("SHOW_STAND", v_stand);
            map.put("SHOW_RESULT", result);//判断是否是乱码
            if (isok == 1) {
                map.put("SHOW_TIME", "OK");
                if (module != null) {
                    if (module.getresult() < 1)
                        module.setresult(isok);
                }
            } else if (isok == 2) {
                t_isok = false;
                map.put("SHOW_TIME", "N.OK");
                Common.cartype.Result = isok; //结果不OK
                if (module != null) {
                    if (module.getresult() < 2)
                        module.setresult(isok);
                    module.addcontext(content + ":" + result);
                }
            } else
                map.put("SHOW_TIME", "---");
            updateData.add(map);
            m_handler.obtainMessage(Message.MSG_ShowArray, map).sendToTarget();
        }

        private void ShowProcessList(int id, String content, String result, int isok) {
            //SimpleDateFormat  sDateFormat   =   new   SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //日期格式
            //String date = sDateFormat.format(new java.util.Date());  //当前时间
            HashMap<String, String> map = new HashMap<String, String>();
            //id_num++;
            map.put("SHOW_ID", id + "");
            map.put("SHOW_CONTEXT", content);
            byte[] a = {0x00};
            byte[] b = {(byte) 0xFF};//用""替换乱码
            if (result.contains(new String(a))) {
                result = result.replace(new String(a), "");
            }
            if (result.contains(new String(b))) {
                result = result.replace(new String(b), "");
            }
            map.put("SHOW_RESULT", result);//判断是否是乱码
            if (isok == 1) {
                map.put("SHOW_TIME", "OK");
                if (module != null) {
                    if (module.getresult() < 1)
                        module.setresult(isok);
                }
            } else if (isok == 2) {
                t_isok = false;
                map.put("SHOW_TIME", "N.OK");
                Common.cartype.Result = isok; //结果不OK
                if (module != null) {
                    if (module.getresult() < 2)
                        module.setresult(isok);
                    module.addcontext(content + ":" + result);
                }
            } else
                map.put("SHOW_TIME", "---");
            updateData.add(map);
            m_handler.obtainMessage(Message.MSG_ShowArray, map).sendToTarget();
        }

        private void ShowProcessListHide(String id, String content, String result, int isok) {
            //SimpleDateFormat  sDateFormat   =   new   SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //日期格式
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("SHOW_ID", id);
            map.put("SHOW_CONTEXT", content);
            map.put("SHOW_RESULT", result);
            if (isok == 1)
                map.put("SHOW_TIME", "OK");
            else if (isok == 2) {
                map.put("SHOW_TIME", "N.OK");
                Common.cartype.Result = isok; //结果不OK
            } else
                map.put("SHOW_TIME", "---");
            m_handler.obtainMessage(Message.MSG_ShowArrayHide, map).sendToTarget();
        }

        private void ShowProcessListHide(int id, String content, String result, int isok) {
            //SimpleDateFormat  sDateFormat   =   new   SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //日期格式
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("SHOW_ID", id + "");
            map.put("SHOW_CONTEXT", content);
            map.put("SHOW_RESULT", result);
            if (isok == 1)
                map.put("SHOW_TIME", "OK");
            else if (isok == 2) {
                map.put("SHOW_TIME", "N.OK");
                Common.cartype.Result = isok; //结果不OK
            } else
                map.put("SHOW_TIME", "---");
            m_handler.obtainMessage(Message.MSG_ShowArrayHide, map).sendToTarget();
        }

        //第一步，先连接上box,
        //返回值：  -1，直接退出,0 -- 连接成功
        private int ConnectToBox() {
            int i;
            //开始记录日志
            //m_com.exit = false;
            //			m_com.SetStartRecord(new String(Common.cartype.vin));
            //获取序列号
            if (Common.Debug) Log.i(TAG, "获取序列号...");
            //byte[] serialnum = new byte[12];
            //byte[] softv = new byte[2];
            String v_ver = "";
            for (i = 0; i < Common.cmd_freq; i++) {
                v_ver = m_com.ReadBoxVersion();
                if (v_ver != null && v_ver.length() > 12) {
                    Common.BoxName = v_ver.substring(0, 12);
                    String app = v_ver.substring(v_ver.length() - 4);
                    ShowFuncTip("Box序列号:" + Common.BoxName + "\nBox版本号:V" + app);
                }
                if (v_ver != null && v_ver.length() > 5) break;
                Sleep(50);
                if (exit) return -1;
            }
            if (i >= Common.cmd_freq) {
                ShowFuncTip(R.string.func_show_tip3);
                return -1;
            }

            //显示序列号
            //ShowFuncTip(getString(R.string.func_show_tip5) + "V" + (softv[0]&0xFF) + "." +
            //		Commonfunc.byteToString(softv[1]) + "\n" +
            //		getString(R.string.func_show_tip4)	+ new String(serialnum));
            ShowFuncTip(v_ver);
            Common.BoxName = v_ver.substring(0, 12);
            m_com.m_log.PrintLog(Common.BoxName);
            Sleep(500);
            return 0;
        }

        //上传数据并打印保存
        private boolean SendDataToDbAndPrint(String Pname, int Printnum) {
            if (Common.web_enable == false) {
                ArrayList<String> list = new ArrayList<String>();
                list.add(new String(Common.cartype.vin));
                list.add(Common.cartype.config);//配置码
                list.add(Pname);//工位
                list.add(Common.cartype.name);//车型
                list.add(Common.cartype.name);//打印单据中的name
                list.add(Common.cartype.date);
                list.add(Common.cartype.box_serialnum);
                //增加的这里打印密码本
                list.add(Common.PrintPinnum + "");
                //增加的这里打印PIN码
                list.add(Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
                //打印结果
                list.add(Printnum + "");
                list.add(Common.cartype.Result + "");
                list.add("null");
                list.add("0");
                list.add("null");
                ServerSocket v_server = new ServerSocket();
                String ip = Common.Server_IP1;
                for (int i = 0; i < 3; i++) {//TODO
                    ShowFuncTip("连接服务器,第" + (i + 1) + "次...");
                    if (v_server.ConnectServer(ip, Common.Server_PORT)) {
                        String result = "1:" + list.toString() + "," + t_print.toString();
                        v_server.SendDataToServer(String.valueOf(100000 + result.getBytes().length).substring(1, 6) + result);
                        Sleep(1000);//上传详细数据
                        String ups = "5:" + updateData.size() + ":" + new String(Common.cartype.vin) + ";" + new String(updateData.toString());
                        v_server.SendDataToServer(String.valueOf(100000 + ups.getBytes().length).substring(1, 6) + ups);
                        Sleep(1000);
                        v_server.close();
                        break;
                    }
                    if (i == 2 && ip.equals(Common.Server_IP1)) {
                        i = 0;
                        ip = Common.Server_IP2;
                    }
                    Sleep(Common.waittime);
                }
                //保存数据到本地
                SaveDataToDb("1:" + list.toString() + "," + t_print.toString(), m_listshowArray);
            }
            //上传web服务器
            else {
                JSONObject jsonmain = new JSONObject();
                try {
                    jsonmain.put("resultVin", new String(Common.cartype.vin));
                    jsonmain.put("resultTestnum", "" + 1);
                    jsonmain.put("resultCartype", Common.cartype.cartype_w);
                    jsonmain.put("resultCar", Common.cartype.name);
                    jsonmain.put("resultStation", Pname);
                    jsonmain.put("resultDevice", Common.cartype.box_serialnum);
                    jsonmain.put("resultCarname", Common.cartype.name);
                    jsonmain.put("resultPrintnum", "0");
                    jsonmain.put("resultPrint", t_print.toString());
                    jsonmain.put("resultPin", Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
                    jsonmain.put("resultEsk", "");
                    jsonmain.put("resultColor", "");
                    jsonmain.put("resultAppver", getResources().getString(R.string.Version));
                    jsonmain.put("resultUp2mes", "0");
                    jsonmain.put("resultUser", "test");
                    jsonmain.put("fileName", m_com.m_log.m_filename);
                    jsonmain.put("resultLog", "");
                    jsonmain.put("resultCartime", Common.cartype.start_time);
                    jsonmain.put("resultCardate", Common.cartype.date);
                    if (Common.cartype.Result <= 1)
                        jsonmain.put("resultResult", "OK");
                    else
                        jsonmain.put("resultResult", "NG");
                    JSONArray array = new JSONArray();
                    for (int k = 0; k < updateData.size(); k++) {
                        JSONObject jsondetail = new JSONObject();
                        jsondetail.put("mVin", new String(Common.cartype.vin));
                        jsondetail.put("mTestcode", "" + (120 + Common.DeFault_Eol));
                        jsondetail.put("mContext", updateData.get(k).get("SHOW_CONTEXT"));
                        jsondetail.put("mTestdata", updateData.get(k).get("SHOW_RESULT"));
                        jsondetail.put("mStand", updateData.get(k).get("SHOW_STAND"));
                        jsondetail.put("mResult", updateData.get(k).get("SHOW_TIME"));
                        array.put(k, jsondetail);
                    }
                    jsonmain.put("tableResultDetails", array);
                    // 上传
                    Long v_upfileid = (long) 0;
                    for (int k = 0; k < 3; k++) {
                        ShowFuncTip("上传服务器数据[第" + (k + 1) + "次]...");
                        m_com.m_log.PrintLog("UpAddr:" + Common.web_upresult);
                        m_com.m_log.PrintLog(t_print.toString());
                        String res = HttpRequest.sendPostToMyMes(Common.web_upresult, jsonmain.toString().replace(">", ""));
                        m_com.m_log.PrintLog(res);
                        if (res.indexOf("200") > 0) //ok
                        {
                            JSONObject resjson = new JSONObject(res);
                            JSONObject son = resjson.getJSONObject("data");
                            if (son != null)
                                v_upfileid = son.getLong("resultId");
                            ShowFuncTip("上传服务器数据成功");
                            Common.updata_isok = true;
                            break;
                        } else {
                            Common.updata_isok = false;
                        }
                    }
                    if (v_upfileid > 0) {
                        for (int k = 0; k < 3; k++) {
                            ShowFuncTip("上传日志文件...[第" + (k + 1) + "次]");
                            m_com.m_log.PrintAppend("UpFile:" + Common.web_upfile);
                            if (uploadFiles(Common.web_upfile, m_com.m_log.getFilePath(), v_upfileid) == true) {
                                ShowFuncTip("上传日志文件成功");
                                break;
                            } else
                                ShowFuncTip("上传日志文件失败");
                        }
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //保存数据到本地
                SaveDataToDb("1:" + jsonmain.toString() + "," + t_print.toString(), m_listshowArray);
            }
            return true;
        }


        private boolean SetCanInitial(String cartype, String module) {
            //获取配置文件路径
            String v_path = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/" + "can.ini";
            Ini inican;
            try {
                inican = new Ini(new File(v_path));
                Profile.Section sec = inican.get(module);
                int mode = 0;
                if (sec.get("CAN").equals("PCAN"))
                    mode = 1;    //20150801后重新纠正
                else if (sec.get("CAN").equals("BCAN"))
                    mode = 2;
                if (Common.Debug) Log.i(TAG, "CAN_mode = " + mode);
                int baud = Integer.valueOf(sec.get("BAUD"));
                if (Common.Debug) Log.i(TAG, "BAUD = " + baud);
                byte[] can_addr = new byte[4];
                String t1 = sec.get("ID_SEND");
                int v_id = Commonfunc.HexStringtoInt(t1);
                can_addr[0] = (byte) ((v_id / 0x100) & 0xFF);
                can_addr[1] = (byte) (v_id & 0xFF);
                String t2 = sec.get("ID_RECV");
                v_id = Commonfunc.HexStringtoInt(t2);
                can_addr[2] = (byte) ((v_id / 0x100) & 0xFF);
                can_addr[3] = (byte) (v_id & 0xFF);
                m_com.m_log.setCanId(can_addr);
                if (Common.Debug)
                    Log.i(TAG, "CAN_ID = " + Commonfunc.bytesToHexString(can_addr, 0, can_addr.length));
                boolean init = SetCanInit(mode, baud, can_addr, 2);
                if (!init) {//初始化失败
                    t_isok = false;
                    Common.cartype.Result = 2;
                }
                return init;
            } catch (InvalidFileFormatException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return true;
        }

        private boolean SetCanInitial(String cartype, String module, int[] Pcanid) {
            //获取配置文件路径
            String v_path = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/" + "can.ini";
            Ini inican;
            try {
                inican = new Ini(new File(v_path));
                Profile.Section sec = inican.get(module);
                if (sec == null) return false;
                int mode = 0;
                if (sec.get("CAN").equals("PCAN"))
                    mode = 1;    //20150801后重新纠正
                else if (sec.get("CAN").equals("BCAN"))
                    mode = 2;
                if (Common.Debug) Log.i(TAG, "CAN_mode = " + mode);
                int baud = Integer.valueOf(sec.get("BAUD"));
                if (Common.Debug) Log.i(TAG, "BAUD = " + baud);
                byte[] can_addr = new byte[4];
                String t1 = sec.get("ID_SEND");
                int v_id = Commonfunc.HexStringtoInt(t1);
                if (Pcanid != null)
                    Pcanid[0] = v_id;
                can_addr[0] = (byte) ((v_id / 0x100) & 0xFF);
                can_addr[1] = (byte) (v_id & 0xFF);
                String t2 = sec.get("ID_RECV");
                v_id = Commonfunc.HexStringtoInt(t2);
                if (Pcanid != null)
                    Pcanid[1] = v_id;
                can_addr[2] = (byte) ((v_id / 0x100) & 0xFF);
                can_addr[3] = (byte) (v_id & 0xFF);
                if (Common.Debug)
                    Log.i(TAG, "CAN_ID = " + Commonfunc.bytesToHexString(can_addr, 0, can_addr.length));
                boolean init = SetCanInit_new(mode, baud);
                if (!init) {//初始化失败
                    t_isok = false;
                    Common.cartype.Result = 2;
                }
                return init;
            } catch (InvalidFileFormatException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return true;
        }

        private boolean SetCanInitial_Flash(String cartype, String module, int[] Pcanid) {
            //获取配置文件路径
            String v_path = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/" + "can.ini";
            Ini inican;
            try {
                inican = new Ini(new File(v_path));
                Profile.Section sec = inican.get(module);
                int mode = 0;
                if (sec.get("CAN").equals("PCAN"))
                    mode = 1;
                else
                    mode = 2;
                if (Common.Debug) Log.i(TAG, "CAN_mode = " + mode);
                int baud = Integer.valueOf(sec.get("BAUD"));
                if (Common.Debug) Log.i(TAG, "BAUD = " + baud);
                byte[] can_addr = new byte[4];
                String t1 = sec.get("ID_SEND");
                int v_id = Commonfunc.HexStringtoInt(t1);
                can_addr[0] = (byte) ((v_id / 0x100) & 0xFF);
                can_addr[1] = (byte) (v_id & 0xFF);
                if (Pcanid != null)
                    Pcanid[0] = v_id;
                String t2 = sec.get("ID_RECV");
                v_id = Commonfunc.HexStringtoInt(t2);
                can_addr[2] = (byte) ((v_id / 0x100) & 0xFF);
                can_addr[3] = (byte) (v_id & 0xFF);
                if (Pcanid != null)
                    Pcanid[1] = v_id;
                if (Common.Debug)
                    Log.i(TAG, "CAN_ID = " + Commonfunc.bytesToHexString(can_addr, 0, can_addr.length));
                return SetCanInit_Flash(mode, baud, can_addr, 2);
            } catch (InvalidFileFormatException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return true;
        }

        //设置can初始化
        private boolean SetCanInit(int mode, long baud, byte[] Pbuf, int num) {
            int i = 0;
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanBaud(baud)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置波特率成功： " + baud);
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanFilter(Pbuf, num)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug)
                Log.i(TAG, "设置CAN id成功： " + Commonfunc.bytesToHexString(Pbuf, 0, Pbuf.length));
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanMode(mode)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CanMode成功：" + mode);
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCommunTimer(10, 2000, 5000, 20)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CAN 时序成功!");
            Sleep(50);
            //设置CAN自动回复帧
            byte[] autocmd = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanAutoFrame(autocmd, 8)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CAN 时序成功!");
            Sleep(50);
            return true;
        }

        private boolean SetCanInit_new(int mode, long baud) {
            int i = 0;
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCommunTimer(10, 2000, 5000, 20)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            Sleep(50);
            byte[] canbuf = {0x30, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00};
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanAutoFrame(canbuf, 8)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CAN 过滤成功!");
            Sleep(50);
            if (Common.CanMode == mode) return true; //诊断新指令，设置过一次就不用再设置20200906

            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanBaud(baud)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置波特率成功： " + baud);
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanMode(mode)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            Common.CanMode = mode;
            if (Common.Debug) Log.i(TAG, "设置CanMode成功：" + mode);
            return true;
        }

        private boolean SetCanInitTimer(int P4) {
            int i;
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCommunTimer(10, 2000, 3000, P4)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CAN 时序成功!");
            return true;
        }

        private boolean SetStandCanAutoFrame(int Pid, byte[] Pdata) {
            int i;
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetStandCanAutoFrame(Pid, Pdata, Pdata.length)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            //if(Common.Debug) Log.i(TAG,"设置CAN 时序成功!");
            return true;
        }

        //设置can初始化
        private boolean SetCanInit_Flash(int mode, long baud, byte[] Pbuf, int num) {
            int i = 0;
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanBaud(baud)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) {
                return false;
            }

            if (Common.Debug) Log.i(TAG, "设置波特率成功： " + baud);
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanFilter(Pbuf, num)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug)
                Log.i(TAG, "设置CAN id成功： " + Commonfunc.bytesToHexString(Pbuf, 0, Pbuf.length));
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanMode(mode)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CanMode成功：" + mode);
            Sleep(50);
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCommunTimer(2, 2000, 3000, 0)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            byte[] canbuf = {0x30, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00};
            for (i = 0; i < Common.cmd_freq; i++) {
                if (m_com.SetCanAutoFrame(canbuf, 8)) break;
                Sleep(50);
            }
            if (i >= Common.cmd_freq) return false;
            if (Common.Debug) Log.i(TAG, "设置CAN 过滤成功!");
            Sleep(50);
            return true;
        }

        private void fun_CX62_PEPS1(Profile.Section section) {
            //			if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            byte[] v_escl_status = new byte[10];    //ESCL状态
            byte[] v_tcu_status = new byte[10];    //TCU状态
            byte[] v_immo_status = new byte[10];    //IMMO状态
            byte[] v_ems_status = new byte[10];    //EMS状态
            byte[] v_trans_status = new byte[10];    //转发器状态
            String status;
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            int key_num = 0;
            int bcm_time = 10;
            int[] canid = new int[2];
            if (Common.cartype.getMap("BM") > 0) {
                if (!SetCanInitial(Common.cartype.cartype, "PEPS1", canid)) return;
            } else {
                if (!SetCanInitial(Common.cartype.cartype, "BCM1", canid)) return;
            }
            for (int i = 1; i < (num + 1); i++) {
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    if (i == 9 || i == 36 || i == 44 || i == 71 || i == 83 || i == 89) {        //切换至IMMO
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1")) return;
                    } else if (i == 25 || i == 42) {    //切换至EMS
                        if (!SetCanInitial(Common.cartype.cartype, "EMS1")) return;
                    } else if (i == 68 || i == 77) { //切换至TCU
                        if (!SetCanInitial(Common.cartype.cartype, "TCU1")) return;
                    } else if (i == 2 || i == 88 || i == 82 || i == 91) { //切换至PEPS
                        if (!SetCanInitial(Common.cartype.cartype, "PEPS1")) return;
                    } else if (i == 6 || i == 13 || i == 28 || i == 93) { //安全认证1
                        if (seed[0] == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 7) {
                        System.arraycopy(Common.cartype.PEPS, 0, cmd, 4, 3);
                    } else if (i == 20 || i == 34 || i == 38 || i == 50 || i == 61 || i == 73 || i == 84) { //安全认证2
                        if (seed[0] == 0) continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 14 || i == 29) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 16) { //IMMO写PIN
                        if ((v_immo_status[1] & 0x04) == 0x04) { //VIN、PIN已写
                            continue;
                        }
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 31) { //EMS写PIN
                        //						if(((v_ems_status[1] >> 2) & 0x01) == 0x01)continue;
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 47) { //提示更换第二把钥匙
                        for (int kk = bcm_time; kk > 0; kk--) {
                            ShowFuncTip("更换钥匙2.." + kk + "s");
                            Sleep(1000);
                        }
                    } else if (i == 48 || i == 59) {
                        if ((v_trans_status[0] & 0x01) != 0x01) { //防盗线圈故障
                            break;
                        }
                    } else if (i == 58) { //提示更换第3把钥匙
                        if (Common.cartype.getMap("手环学习") == 0 || key_num == 3) {//没有BM则不学习第三把钥匙
                            i = 66;
                            continue;
                        }
                        bcm_time = 10;
                        for (int kk = bcm_time; kk > 0; kk--) {
                            ShowFuncTip("更换钥匙3.." + kk + "s");
                            Sleep(1000);
                            if ((kk % 2) == 0) {
                                byte[] cm = {0x02, 0x3E, 0x00};
                                //error = m_com.CanSendAndRecvN2N(cm, cm.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                                error = m_com.CanSendOneOnly(canid[0], cm, cm.length);
                            }
                        }
                    } else if (i == 24 || i == 54 || i == 64) {
                        Sleep(1500);
                    } else if (i == 80) {
                        if (Common.cartype.getMap("TCM") == 1) {
                            i = 88;
                            continue;
                        }
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1")) return;
                    }
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    if (i == 1) {//key on,后等待10秒
                        if (((Readbuf[4] >> 3) & 0x01) == 0x01) { //ON		//
                            for (int k = 4; k > 0; k--) {
                                ShowFuncTip("key on  等待" + k + "s");
                                Sleep(1000);
                            }
                        } else {
                            i--;
                        }
                    } else if (i == 8) {
                        Sleep(2000);
                    } else if (i == 10) {    //读IMMO状态
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[1]) != 0) {
                            ShowProcessList(t_step, step_name, "IMMO已学过", Common.Rok);
                        }
                        if ((v_immo_status[0] & 0x01) != 0x01) { //keyon
                            ShowFuncTip("打开钥匙...");
                            Sleep(500);
                            i--;
                            continue;
                        }
                        if (((v_immo_status[1] >> 1) & 0x01) == 0x01) //VIN已写
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_immo_status[1] >> 2) & 0x01) == 0x01) //VIN已写
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        int nu = (v_immo_status[1] >> 3) & 0x07;
                        status += "KEY:" + nu;
                        ShowProcessList(t_step, step_name, status, Common.Rok);
                    } else if (i == 17) { //读取钥匙数量
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        key_num = (v_immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        if (key_num > 0) {
                            ShowProcessList(t_step, step_name, key_num + "把", Common.Rok);
                            i = 24;
                            continue;
                        }
                    } else if (i == 11 || i == 47 || i == 58) { //读转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        int Result = 1;
                        if ((v_trans_status[0] & 0x01) == 0x01) //防盗线圈故障
                            status = "Ring:1;";
                        else {
                            status = "Ring:0;";
                            Result = 2;
                        }
                        if (((v_trans_status[0] >> 3) & 0x01) == 0x01) //new
                            status += "New:0;";
                        else
                            status += "New:1;";
                        if (((v_trans_status[0] >> 4) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(t_step, step_name, status, Result);
                    } else if (i == 5 || i == 12 || i == 19 || i == 27 || i == 33 || i == 37 || i == 49 || i == 60 || i == 72 || i == 83 || i == 92) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 8);
                    } else if (i == 15 || i == 30) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                    } else if (i == 21 || i == 39 || i == 51 || i == 62 || i == 74 || i == 85) { //学习钥匙
                        ShowProcessList(t_step, step_name, "", Common.Rok);
                        Sleep(2500);
                    } else if (i == 22 || i == 40 || i == 52 || i == 63 || i == 75 || i == 86) { //15检查钥匙学习结果,33检查EMS学习SK情况,45key2,63tcu,68 immo teach tcu,77immo teach escl
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03) { //继续
                            if (i == 63) continue;
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(step_id, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(step_id, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(step_id, step_name, "Routine failure and routine not run!", Common.Rnok);
                            break;
                        }
                    } else if (i == 24) { //检查转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        if ((v_trans_status[0] & 0x10) == 0x10) //已经配对
                            ShowProcessList(step_id, step_name, "", Common.Rok);
                        else {
                            ShowProcessList(step_id, step_name, Readbuf[5] + "", Common.Rnok);
                        }
                    } else if (i == 26 || i == 32) { //读取EMS状态
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x01) == 0x01) //VIN
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_ems_status[1] >> 2) & 0x01) == 0x01) //PIN
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        if (((v_ems_status[1] >> 3) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(step_id, step_name, status, Common.Rok);
                        if (i == 32) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                i = 43;
                                continue;
                            }
                        }
                    } else if (i == 43) { //EMS状态,SK学习结果
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x07) == 0x07) //EMS已经学习过
                            ShowProcessList(step_id, step_name, "VIN/PIN/SK", Common.Rok);
                        else {
                            ShowProcessList(step_id, step_name, "SK", Common.Rnok);
                        }
                    } else if (i == 45) { //key off
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);//第3次01 08
                        int nu = (v_immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        if (nu > 1) {
                            i = 54;
                            continue;
                        }
                        if ((v_immo_status[0] & 0x01) == 0x01) { //ON
                            ShowFuncTip("KEY OFF...");
                            Sleep(100);
                            i--;
                        }
                    } else if (i == 46) { //检查key on
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);//第四次
                        if ((v_immo_status[0] & 0x01) == 0x00) { //ON
                            ShowFuncTip("KEY ON...");
                            Sleep(100);
                            i--;
                        }
                    } else if (i == 81) { //key off
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[0] & 0x01) == 0x01) { //ON
                            ShowFuncTip("切换至ACC档...");
                            Sleep(500);
                            i--;
                        }
                    } else if (i == 90) {//key on
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[0] & 0x01) == 0x00) { //0FF
                            ShowFuncTip("开钥匙KEY ON...");
                            Sleep(500);
                            i--;
                        } else { //等10秒
                            for (int k = 2; k > 0; k--) {
                                ShowFuncTip("等待:" + k + "s");
                                Sleep(1000);
                            }
                        }
                    } else if (i == 67) { //检查钥匙数量
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        key_num = (v_immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        boolean v_isc = false;
                        if (Common.cartype.getMap("BM") > 0)
                            v_isc = true;
                        if (key_num == 2) { //OK
                            ShowProcessList(step_id, step_name, "2把", Common.Rok);
                        } else if (key_num == 3 && v_isc) { //OK
                            ShowProcessList(step_id, step_name, "3把", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, key_num + "把", Common.Rnok);
                            break;
                        }
                    } else if (i == 55 || i == 65 || i == 79) { //EMS\IMMO ClearDTC
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        if (i == 79) {//TCU做完退出
                            i = 90;
                            continue;
                        }
                    } else if (i == 78) { //检查TCU状态结果
                        System.arraycopy(Readbuf, 4, v_tcu_status, 0, 3);
                        if (v_tcu_status[0] != 0x0F) { //不OK
                            ShowProcessList(t_step, step_name, ("TCU authentication failure!"), Common.Rnok);
                        } else
                            ShowProcessList(t_step, step_name, ("TCU OK!"), Common.Rok);
                    } else if (i == 82) { //ESCL学习结果
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x00) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL 已经学习过!", Common.Rok);
                            i = 88;
                            continue;
                        } else
                            ShowProcessList(t_step, step_name, "TSCL 开始学习!", Common.Rok);
                    } else if (i == 88) {//ESCL学习结果
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x01) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL authentication failure", Common.Rnok);
                        } else
                            ShowProcessList(t_step, step_name, "TSCL OK!", Common.Rok);
                    } else if (i == 95) { //学习结果
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03) { //继续
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02)
                            ShowProcessList(t_step, step_name, "OK", Common.Rok);
                        else {
                            ShowProcessList(t_step, step_name, getResources().getString(R.string.execute_success), Common.Rok);
                        }
                    } else {
                        ShowProcessList(t_step, step_name, "", Common.Rok);
                    }
                } else if (step_t.substring(0, 3).equals("SHW")) { //SHW
                    int v_add1 = step_t.indexOf("<");
                    int v_add2 = step_t.indexOf(">");
                    if (Common.Debug) Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                    String v_data1 = step_t.substring(4, v_add1);
                    int v_time = Integer.valueOf(step_t.substring(v_add1 + 1, v_add2));
                    if (v_data1.equals("NO") == true) { //直接显示文本内容
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) { //发链路
                            byte[] cmd = new byte[]{0x02, 0x3E, 0x00};
                            error = m_com.CanSendOneOnly(canid[0], cmd, cmd.length);
                            Sleep(2000);
                        }
                    }
                }
            }
        }

        private void fun_CX62_keylearn1(Profile.Section section) {
            int[] canid = new int[2];
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            byte[] v_trans_status = new byte[10];    //转发器状态
            String status;
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            int bcm_time = 10;
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(0, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 0; i < num; i++) {
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    if (i == 1) { //提示更换第3把钥匙
                        bcm_time = 10;
                        for (int kk = bcm_time; kk > 0; kk--) {
                            ShowFuncTip("更换钥匙3.." + kk + "s");
                            Sleep(1000);
                            if ((kk % 2) == 0) {
                                byte[] cm = {0x02, 0x3E, 0x00};
                                error = m_com.CanSendOneOnly(canid[0], cm, cm.length);
                                //error = m_com.CanSendAndRecvN2N(cm, cm.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                            }
                        }
                    } else if (i == 4) { //安全认证2
                        if (seed[0] == 0) continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    }
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    if (i == 0) {
                        byte[] immo_status = new byte[4];
                        System.arraycopy(Readbuf, 4, immo_status, 0, 4);
                        int key_num = (immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        if (key_num == 3) {
                            ShowProcessList(t_step, step_name, "手环已学习!", Common.Rok);
                            break;
                        }
                    } else if (i == 1) { //读转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        int Result = 1;
                        if ((v_trans_status[0] & 0x01) == 0x01) //防盗线圈故障
                            status = "Ring:1;";
                        else {
                            status = "Ring:0;";
                            Result = 2;
                        }
                        if (((v_trans_status[0] >> 3) & 0x01) == 0x01) //new
                            status += "New:0;";
                        else
                            status += "New:1;";
                        if (((v_trans_status[0] >> 4) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(t_step, step_name, status, Result);
                    } else if (i == 3) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 8);
                    } else if (i == 5) { //学习钥匙
                        ShowProcessList(t_step, step_name, "", Common.Rok);
                        Sleep(2500);
                    } else if (i == 6) { //15检查钥匙学习结果,33检查EMS学习SK情况,45key2,63tcu,68 immo teach tcu,77immo teach escl
                        if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(step_id, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(step_id, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(step_id, step_name, "Routine failure and routine not run!", Common.Rnok);
                            break;
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_BCM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            int time = 10;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4 || i == 12) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    } else if (i == 13) { //决定是否要做遥控钥匙匹配
                        if (Common.cartype.getMap("PEPS") > 0) {
                            i = 18;
                            continue;
                        }
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3 || i == 11) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 7) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else if (i == 9) { //读取点火状态
                        if (((Readbuf[4] >> 3) & 0x01) == 0x01) { //ON
                            ShowFuncTip("关钥匙KEY OFF...");
                            Sleep(800);
                            i--;
                        }
                    } else if (i == 14) { //查询遥控钥匙学习结果
                        if (time > 0) {
                            i--;
                            ShowProcessList(step_id, step_name, time + "S", Common.Rok);
                            Sleep(500);
                            time--;
                        }
                    } else if (i == 17) { //读取学习数量
                        if (Readbuf[4] != 0x01) {
                            i = 8;
                            continue;
                        }
                        ShowProcessList(step_id, step_name, Readbuf[4] + "把", Common.Rok);
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_BCM2(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 8);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 8) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_ICM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 10) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_BM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 6) { //写pin
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 9) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_FCW1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 8) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }


        private void fun_CX62_RRM1(Profile.Section section) {
            //can初始化
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))) return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) {//安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    } else if (i == 6) { //写vin
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) {//通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 7) {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 9) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(hmpbyte, vin)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else if (i == 10) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_TBOX1(Profile.Section section) {
            //can初始化
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))) return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4 || i == 14) {//安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    } else if (i == 6) { //写vin
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) {//通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3 || i == 13) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 7) {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 10) {//读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(hmpbyte, vin)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else if (i == 9) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rnok);
                        }
                    } else if (i == 16) {
                        if (Readbuf[5] == 0x03) { //运行
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) { //ok
                            ShowProcessList(step_id, step_name, getResources().getString(R.string.connect_success), Common.Rok);
                        } else if (Readbuf[5] == 0x05) { //fail
                            ShowProcessList(step_id, step_name, getResources().getString(R.string.connect_failure), Common.Rok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_RADAR1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 8) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_EPB1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) {//安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.Chery_CX62_EPB_SafeKey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    } else if (i == 5) {//写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 8) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }


        private void fun_CX62_EMS1(Profile.Section section) {
            //can初始化
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))) return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) {//安全认证
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) { //写vin
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) {//通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error > 0) {//其他负响应
                        if ((i == 8) && (Readbuf[3] == 0x22)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                            continue;
                        } else if (error < 100) //异常回复
                        {
                            if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                            {
                                if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                    ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                                else
                                    ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                                continue;
                            }
                        }

                    }
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 8);
                    } else if (i == 5) {//读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                            i += 2;
                        }
                    } else if (i == 7) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rnok);
                        }
                    } else if (i == 8) {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_APM2(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 6) {
                        ShowFuncTip("正在学习防夹...");
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 5) { //复位
                        if (Readbuf[5] == 1) {
                            ShowProcessList(step_id, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "错误码:%02X", Common.Rok);
                            break;
                        }
                    } else if (i == 6) { //读配置
                        if (Readbuf[5] == 3) { //运行
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 5) { //error
                            ShowProcessList(step_id, step_name, ("程序失败或程序没有运行"), Common.Rnok);
                            i++;
                        } else if (Readbuf[5] == 2) { //ok
                            ShowProcessList(step_id, step_name, ("执行完成"), Common.Rok);
                            //玻璃升降结果
                            if ((Readbuf[6] & 0x01) == 0x01)
                                ShowProcessList(step_id, step_name, "左前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(step_id, step_name, "左前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x02) == 0x02)
                                ShowProcessList(step_id, step_name, "右前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(step_id, step_name, "右前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x04) == 0x04)
                                ShowProcessList(step_id, step_name, "左后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(step_id, step_name, "左后玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x08) == 0x08)
                                ShowProcessList(step_id, step_name, "右后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(step_id, step_name, "右后玻璃:初始化失败", Common.Rok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_ABS1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.S32EV_ABS_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 10) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }


        private void fun_CX62_ESP1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.S32EV_ABS_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    } else if (i == 5) { //写配置0100
                        System.arraycopy(Common.cartype.getMapByte("CONFIG"), 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 6) { //复位
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 10) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    } else if (i == 11) { //读配置
                        if (Readbuf[4] == 1) {
                            ShowProcessList(step_id, step_name, "加注成功", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "加注失败", Common.Rnok);
                        }
                    } else {
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_EPS1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] _corner = new byte[2];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) {
                        System.arraycopy(_corner, 0, cmd, 5, 2);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 1) {
                        short corner = (short) (Readbuf[4] * 0x100 + (Readbuf[5] & 0xFF));
                        short cor = (short) (0 - corner);
                        _corner[0] = (byte) ((cor >> 8) & 0xFF);
                        _corner[1] = (byte) (cor & 0xFF);
                        ShowProcessList(step_id, step_name, String.valueOf(corner), Common.Rok);
                    } else if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 5) {
                        if (Readbuf[5] == 0) {
                            ShowProcessList(step_id, step_name, "标定", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "未标定", Common.Rok);
                        }
                        Sleep(2000);
                    } else if (i == 6) {
                        int result = (Readbuf[4] * 0x100 + (Readbuf[5] & 0xFF));
                        if (result <= 3 && result >= -3) {
                            ShowProcessList(step_id, step_name, "合格", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "不合格", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_EPB_BiaoDing1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.Chery_CX62_EPB_SafeKey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 5) {
                        if (Readbuf[5] == 0xC0) {
                            ShowProcessList(step_id, step_name, "标定", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "未标定", Common.Rok);
                        }
                        Sleep(2000);
                    } else if (i == 6) {
                        if (Readbuf[4] == 1) {
                            ShowProcessList(step_id, step_name, "合格", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "不合格", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_ESP_BiaoDing1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.S32EV_ABS_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 5) {
                        if (Readbuf[5] == 2) {
                            ShowProcessList(step_id, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "未标定", Common.Rok);
                        }
                    } else if (i == 6) {
                        if (Readbuf[5] == 3) {
                            ShowProcessList(step_id, step_name, "标定中...", Common.Rok);
                            Sleep(1000);
                            i--;
                        } else if (Readbuf[5] == 2) {
                            ShowProcessList(step_id, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, "标定失败", Common.Rok);
                        }
                    } else {  //显示
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_ESP_JiaZhu1(Profile.Section section) {
            m_handler.obtainMessage(Message.MSG_Dialog_InputData, "请输入密码").sendToTarget();
            Common.wait = true;
            while (Common.wait) {
                Sleep(2000);
            }
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.S32EV_ABS_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else {  //显示
                        ShowProcessList(step_id, step_name, "", Common.Rok);
                    }
                }
            }
        }


        private void fun_CX62_SAM1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int[] v_canid = new int[2];
            boolean isinit = false;
            //int [] canid = new int[2];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 1 || i == 4) {
                        SetCanInitial(Common.cartype.cartype, "SAM2", v_canid);
                    } else if (i == 2) {
                        SetCanInitial(Common.cartype.cartype, section.get("MODULE"), v_canid);
                    } else if (i == 3) {
                        if (isinit) {
                            SetCanInitial(Common.cartype.cartype, section.get("MODULE"), v_canid);
                            Sleep(100);
                        }
                    }
                    ///////////////////////命令发送////////////////////////////////
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanSendAndRecvO2O_Spec(v_canid[0], v_canid[1], cmd, cmd.length, Readbuf, Readbuf.length, 1, Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 1) { //判断SAM状态
                        if (Readbuf[4] != 0) {
                            ShowProcessList(step_id, step_name, "SAS错误!", Common.Rnok);
                            break;
                        } else if ((Readbuf[3] & 0x04) != 0x04) { //未标定
                            i++;
                            isinit = true;
                            ShowProcessList(step_id, step_name, "SAM未标定", Common.Rok);
                        } else
                            ShowProcessList(step_id, step_name, "SAM已标定", Common.Rok);
                    } else if (i == 2) { //
                        ShowProcessList(step_id, step_name, "SAS未标定", Common.Rok);
                    } else if (i == 3) {
                        ShowProcessList(step_id, step_name, "SAM执行成功", Common.Rok);
                    } else if (i == 4) {
                        if ((Readbuf[3] & 0x04) != 0x04) { //未标定
                            ShowProcessList(step_id, step_name, "SAM标定失败", Common.Rnok);
                        } else {
                            ShowProcessList(step_id, step_name, "SAM标定成功", Common.Rok);
                        }
                    }
                } else if (step_t.substring(0, 3).equals("SHW")) { //SHW
                    int v_add1 = step_t.indexOf("<");
                    int v_add2 = step_t.indexOf(">");
                    if (Common.Debug) Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                    String v_data1 = step_t.substring(4, v_add1);
                    int v_time = Integer.valueOf(step_t.substring(v_add1 + 1, v_add2));
                    if (v_data1.equals("ON") == true) {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 1).sendToTarget();
                        while (Common.wait) {
                            Sleep(Common.waittime);
                        }
                        ;
                    } else if (v_data1.equals("OFF") == true) {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 2).sendToTarget();
                        while (Common.wait) {
                            Sleep(Common.waittime);
                        }
                        ;
                    } else if (v_data1.equals("NO") == true) { //直接显示文本内容
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) { //发链路
                            byte[] cmd = new byte[]{0x02, 0x3E, 0x00};
                            error = m_com.CanSendOneOnly(v_canid[0], cmd, cmd.length);
                            //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                            Sleep(1500);
                        }
                    } else if (v_data1.equals("NOLINK") == true) { //直接显示文本内容没有链路
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) {
                            Sleep(Common.waittime);
                        }
                        ; //
                    }
                }
            }
        }


        private void fun_CX62_ClearDtc(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            String module = "";
            int[] canid = new int[2];
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");

                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    module = section.get("T" + i + "_MODULE");
                    int select = Common.cartype.getMap(module.substring(0, module.length() - 1));
                    if (module.equals(module.substring(0, module.length() - 1) + select) == false) //不相等
                    {
                        continue;
                    }
                    //can初始化
                    if (!SetCanInitial(Common.cartype.cartype, module, canid)) {
                        ShowProcessList(step_id, step_name, "设置通讯盒", Common.Rnok);
                        return;
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {

                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + "--NOK");

                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    //特殊处理返回结果
                    ShowProcessList(step_id, step_name, "", Common.Rok);
                }
            }
        }

        private void fun_CX62_ReadDtc(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            String module = "";
            int error = 0;
            Sleep(2000);//清故障码后等待一下
            int[] canid = new int[2];
            //这里是CAN线
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    module = section.get("T" + i + "_MODULE");
                    int select = Common.cartype.getMap(module.substring(0, module.length() - 1));
                    if (module.equals(module.substring(0, module.length() - 1) + select) == false) //不相等
                    {
                        continue;
                    }
                    //can初始化
                    if (!SetCanInitial(Common.cartype.cartype, module, canid)) {
                        ShowProcessList(step_id, step_name, "设置通讯盒", Common.Rnok);
                        return;
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {

                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + "--NOK");

                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    //特殊处理返回结果
                    byte[] dtc = new byte[512];
                    ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                    dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                    System.arraycopy(Readbuf, 4, dtc, 1, (dtc[0] & 0xFF) * 4);
                    GetDtcArray(module, dtc, dtclist, 3);
                    if (dtclist.size() > 0) {
                        if (dtclist.size() <= 4) {
                            for (int z = 0; z < dtclist.size(); z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(step_id, step_name, dtclist.get(z).get("NAME") + "--" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                        } else {
                            for (int z = 0; z < 4; z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(step_id, step_name, dtclist.get(z).get("NAME") + "--" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                            clearOrReadDtc.add(module.substring(0, module.length() - 1) + ":" + t_dtc);
                            t_dtc = "";
                            for (int z = 4; z < dtclist.size(); z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(step_id, step_name, dtclist.get(z).get("NAME") + "--" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                        }
                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + ":" + t_dtc);

                    } else {
                        ShowProcessList(step_id, step_name, "无故障", Common.Rok);
                    }
                }
            }
        }


        private void fun_CX62_ReadConfig(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int[] canid = new int[2];
            int error = 0;
            String flash = HttpRequest.getInfoFromMes(new String(Common.cartype.vin), "Get_ECUInfo");
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    String module = section.get("T" + i + "_MODULE");
                    int select = Common.cartype.getMap(module.substring(0, module.length() - 1));
                    if (select == 0) continue;
                    //can初始化
                    if (i != 12) {
                        if (!SetCanInitial(Common.cartype.cartype, module.substring(0, module.length() - 1) + select, canid)) {
                            ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                            return;
                        }
                        //if(!SetCanInitial(Common.cartype.cartype,module.substring(0, module.length() - 1)+select))return;
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    if (i == 11) {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (Arrays.equals(vin, Common.cartype.vin)) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rnok);
                        }
                    } else if (i == 12) {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        String[] fileName = flash.split("\\*");
                        String v_comp = fileName[3];
                        //v_comp = v_comp.substring(0, v_comp.indexOf("/"));
                        if (fileName.length > 3) {
                            if (new String(vin).equals(v_comp)) {
                                ShowProcessList(step_id, step_name, new String(vin) + "[" + v_comp + "]", Common.Rok);
                            } else {
                                ShowProcessList(step_id, step_name, new String(vin) + "[" + v_comp + "]", Common.Rnok);
                            }
                        } else {
                            ShowProcessList(step_id, step_name, "从MES获取版本失败", Common.Rnok);
                        }
                    } else {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        byte[] hmpbyte = Common.cartype.getMapByte("CONFIG");
                        if (Arrays.equals(vin, hmpbyte)) {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), Common.Rnok);
                        }
                    }
                }
            }
        }

        private void fun_CX62_OBD_check(Profile.Section section) {
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"))) {
                return;
            }
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            boolean vinError = false;
            String vin = "";
            String obd = "";
            String odo = "0";
            String emsModuleId = "";
            String emsName = "";
            String ems_calId1 = "";
            String ems_calId2 = "";
            String ems_calId3 = "";
            String ems_cvn1 = "";
            String ems_cvn2 = "";
            String ems_cvn3 = "";
            String tcuModuleId = "";
            String tcuName = "";
            String tcu_calId1 = "";
            String tcu_calId2 = "";
            String tcu_calId3 = "";
            String tcu_cvn1 = "";
            String tcu_cvn2 = "";
            String tcu_cvn3 = "";
            String opass = "";
            try {
                Ini inican = new Ini(new File(Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/" + "can.ini"));
                Section sec = inican.get("EMS1");
                emsModuleId = sec.get("ID_SEND") + "/" + sec.get("ID_RECV");
                if (Common.cartype.getMap("TCM") > 0) {
                    sec = inican.get("TCM1");
                    tcuModuleId = sec.get("ID_SEND") + "/" + sec.get("ID_RECV");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            SetCanInitTimer(15);
            int v_req = 0x7DF;
            int v_res = 0x7E8;
            byte[] v_autocmd = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
            SetStandCanAutoFrame(0x7E0, v_autocmd);
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    cmdlen++;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
					/*if(i==7){
						if(Common.cartype.getMap("TCM")==0) break;
						if(!SetCanInitial(Common.cartype.cartype,"TCM1")) break;
					}*/
                    if (i == 7) {
                        v_req = 0x7E1;
                        v_res = 0x7E9;
                        SetStandCanAutoFrame(0x7E1, v_autocmd);
                        int v_len = Common.cartype.getMap("TCM");
                        if (v_len <= 0) break;
                        tcuModuleId = String.format("%02X", v_req) + "/" + String.format("%02X", v_res);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    error = m_com.CanOne2OneUDS(v_req, v_res, cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 3);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (i > 6) {
                                if ("29".equals(obd) == false)
                                    continue;
                            }
                            vinError = true;
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            continue;
                        }
                    } else if (error > 0) {//其他负响应
                        ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rnok);
                        continue;
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 1) {    //读seed
                        byte[] res = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, res, 0, res.length);
                        vin = new String(res);
                        if (Arrays.equals(res, Common.cartype.vin)) {
                            ShowProcessList(step_id, step_name, new String(res), Common.Rok);
                        } else {
                            vinError = true;
                            ShowProcessList(step_id, step_name, new String(res), Common.Rnok);
                        }
                    } else if (i == 2) {
                        obd = String.format("%x", Readbuf[3] & 0xFF);
                        ShowProcessList(step_id, step_name, obd, Common.Rok);
                    } else if (i == 3) {//汽车里程
                        int result = (Readbuf[3] & 0xFF) * 0x1000000 + (Readbuf[4] & 0xFF) * 0x10000 + (Readbuf[5] & 0xFF) * 0x100 + (Readbuf[6] & 0xFF);
                        if (result % 10 == 0) {
                            odo = result / 10 + "KM";
                        } else {
                            odo = ((float) result / 10) + "KM";
                        }
                        ShowProcessList(step_id, step_name, odo, Common.Rok);
                    } else if (i == 4 || i == 7) {//读取ECU名称
                        byte[] res = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, res, 0, res.length);
                        if (i == 4) {
                            emsName = new String(res);
                        } else {
                            tcuName = new String(res);
                        }
                        ShowProcessList(step_id, step_name, new String(res), Common.Rok);
                    } else if (i == 5 || i == 8) {//读取CAL ID
                        String calshow = "";
                        for (int j = 0; j < Readbuf[3]; j++) {
                            byte[] id = new byte[16];
                            System.arraycopy(Readbuf, 4 + 16 * j, id, 0, id.length);
                            if (i == 5) {
                                if (j == 0) {
                                    ems_calId1 = new String(id);
                                } else if (j == 1) {
                                    ems_calId2 = new String(id);
                                } else if (j == 2) {
                                    ems_calId3 = new String(id);
                                }
                                calshow = new String(id);
                            } else {
                                if (j == 0) {
                                    tcu_calId1 = new String(id);
                                    calshow = tcu_calId1;
                                } else if (j == 1) {
                                    //tcu_calId2=new String(id);
                                    tcu_calId2 = Commonfunc.bytesToHexStringP(id, 0, 4);
                                    calshow = tcu_calId2;
                                } else if (j == 2) {
                                    tcu_calId3 = new String(id);
                                    calshow = tcu_calId3;
                                }
                            }
                            ShowProcessList(step_id, step_name, calshow, Common.Rok);
                        }
                    } else if (i == 6 || i == 9) {//读取CVN
                        for (int j = 0; j < Readbuf[3]; j++) {
                            byte[] id = new byte[4];
                            System.arraycopy(Readbuf, 4 + 4 * j, id, 0, id.length);
                            if (i == 6) {
                                if (j == 0) {
                                    ems_cvn1 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                } else if (j == 1) {
                                    ems_cvn2 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                } else if (j == 2) {
                                    ems_cvn3 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                }
                            } else {
                                if (j == 0) {
                                    tcu_cvn1 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                } else if (j == 1) {
                                    tcu_cvn2 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                } else if (j == 2) {
                                    tcu_cvn3 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                }
                            }
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(id, 0, id.length), Common.Rok);
                        }
                    }
                }
            }
            SetStandCanAutoFrame(0, v_autocmd);
            if (vinError) {//读出来的和扫描的不一致就不上传
                m_com.m_log.PrintLog("VIN:" + vin + ",vin not same one.");
//				ShowProcessList(step_id,"上传OBD信息","上传失败",Common.Rnok);
                return;
            }
            if ("".equals(obd) || "".equals(odo) || "".equals(emsName) || "".equals(ems_calId1) || "".equals(ems_cvn1)) {
                opass = "0";
            } else if (Common.cartype.getMap("TCM") > 0 && ("".equals(tcuName) || "".equals(tcu_calId1) || "".equals(tcu_cvn1))) {
                opass = "0";
            } else {
                opass = "1";
            }
            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            String param = "<root><vin>" + vin + "</vin><Type>01</Type><Result>ok</Result><OBDDataDetail><EMS><obd_VIN>" +
                    vin + "</obd_VIN><obd>" + obd + "</obd><odo>" + odo + "</odo><moduleID>" + emsModuleId + "</moduleID><ECUname>" +
                    emsName + "</ECUname><calID_01>" + ems_calId1 + "</calID_01><calID_02>" + ems_calId2 + "</calID_02><calID_03>" +
                    ems_calId3 + "</calID_03><cvn_01>" + ems_cvn1 + "</cvn_01><cvn_02>" + ems_cvn2 + "</cvn_02><cvn_03>" +
                    ems_cvn3 + "</cvn_03></EMS><TCU><moduleID>" + tcuModuleId + "</moduleID><ECUname>" +
                    tcuName + "</ECUname><calID_01>" + tcu_calId1 + "</calID_01><calID_02>" + tcu_calId2 + "</calID_02><calID_03>" +
                    tcu_calId3 + "</calID_03><cvn_01>" + tcu_cvn1 + "</cvn_01><cvn_02>" + tcu_cvn2 + "</cvn_02><cvn_03>" +
                    tcu_cvn3 + "</cvn_03></TCU><opass>" + opass + "</opass><otestdate>" + date + "</otestdate><O_created_author>CP8</O_created_author>" +
                    "<O_CarManuf>SYC-CB</O_CarManuf><O_Operation>CP8</O_Operation><O_Operator>CP8</O_Operator></OBDDataDetail></root>";
            byte[] nul = {0};//替换00乱码
            if (param.contains(new String(nul))) {
                param = param.replace(new String(nul), "");
            }
            m_com.m_log.PrintLog(param);
            String result = HttpRequest.uploadOBDToMes(param);
            m_com.m_log.PrintLog(result);
            if (result != null && result.contains("成功")) {
                ShowProcessList(step_id, "上传OBD信息", "上传成功", Common.Rok);
            } else {
//				ShowProcessList(step_id,"上传OBD信息","上传失败",Common.Rnok);
            }
        }

        private void fun_CX62_OBD_upload(boolean isDct) {
            m_handler.obtainMessage(Message.MSG_Dialog_InputData, "请输入密码").sendToTarget();
            Common.wait = true;
            while (Common.wait) {
                Sleep(2000);
            }
            String vin = new String(Common.cartype.vin);
            String emsModuleId = "7E0/7E8";
            String emsName = "ECM-EngineControl";
            String tcuModuleId = "";
            String tcuName = "";
            String tcu_calId1 = "";
            String tcu_cvn1 = "";
            if (isDct) {
                tcuName = "TCM-TransmisCtrl";
                tcuModuleId = "7E1/7E9";
                tcu_calId1 = "D71BA9E7";
                tcu_cvn1 = "D71BA9E7";
            }
            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            String param = "<root><vin>" + vin + "</vin><Type>01</Type><Result>ok</Result><OBDDataDetail><EMS><obd_VIN>" +
                    vin + "</obd_VIN><obd>29</obd><odo>0</odo><moduleID>" + emsModuleId + "</moduleID><ECUname>" +
                    emsName + "</ECUname><calID_01>" + ems_calId + "</calID_01><calID_02></calID_02><calID_03>" +
                    "</calID_03><cvn_01>" + ems_cvn + "</cvn_01><cvn_02></cvn_02><cvn_03>" +
                    "</cvn_03></EMS><TCU><moduleID>" + tcuModuleId + "</moduleID><ECUname>" +
                    tcuName + "</ECUname><calID_01>" + tcu_calId1 + "</calID_01><calID_02></calID_02><calID_03>" +
                    "</calID_03><cvn_01>" + tcu_cvn1 + "</cvn_01><cvn_02></cvn_02><cvn_03>" +
                    "</cvn_03></TCU><opass>1</opass><otestdate>" + date + "</otestdate><O_created_author>CP8</O_created_author>" +
                    "<O_CarManuf>SYC-CB</O_CarManuf><O_Operation>CP8</O_Operation><O_Operator>CP8</O_Operator></OBDDataDetail></root>";
            m_com.m_log.PrintLog(param);
            String result = HttpRequest.uploadOBDToMes(param);
            m_com.m_log.PrintLog(result);
            if (result != null && result.contains("成功")) {
                ShowProcessList("100", "上传OBD信息", "上传成功", Common.Rok);
            } else {
//				ShowProcessList("100","上传OBD信息","上传失败",Common.Rnok);
            }
        }

        private void fun_CX62_OBD_check_old(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            boolean vinError = false;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            String vin = "";
            String obd = "";
            String odo = "";
            String ecuName = "";
            String ems_calId1 = "";
            String ems_calId2 = "";
            String ems_calId3 = "";
            String ems_cvn1 = "";
            String ems_cvn2 = "";
            String ems_cvn3 = "";
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 7) {
                        if (!SetCanInitial(Common.cartype.cartype, "TCU1")) return;
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 1) {    //读seed
                        byte[] res = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, res, 0, res.length);
                        vin = new String(res);
                        if (Arrays.equals(res, Common.cartype.vin)) {
                            ShowProcessList(step_id, step_name, vin, Common.Rok);
                        } else {
                            vinError = true;
                            ShowProcessList(step_id, step_name, vin, Common.Rnok);
                        }
                    } else if (i == 2) {
//						if((Readbuf[3]&0xFF)==0x01){
//							obd="OBD II";
//						}else if((Readbuf[3]&0xFF)==0x02){
//							obd="OBD";
//						}else if((Readbuf[3]&0xFF)==0x03){
//							obd="OBD and OBD II";
//						}else if((Readbuf[3]&0xFF)==0x04){
//							obd="OBD I";
//						}else if((Readbuf[3]&0xFF)==0x05){
//							obd="NO OBD";
//						}else if((Readbuf[3]&0xFF)==0x06){
//							obd="EOBD";
//						}else if((Readbuf[3]&0xFF)==0x07){
//							obd="EOBD and OBD II";
//						}else if((Readbuf[3]&0xFF)==0x08){
//							obd="EOBD and OBD";
//						}else if((Readbuf[3]&0xFF)==0x09){
//							obd="EOBD, OBD and OBD II";
//						}else if((Readbuf[3]&0xFF)==0x0A){
//							obd="JOBD";
//						}else if((Readbuf[3]&0xFF)==0x0B){
//							obd="JOBD and OBD II";
//						}else if((Readbuf[3]&0xFF)==0x0C){
//							obd="JOBD and EOBD";
//						}else if((Readbuf[3]&0xFF)==0x0D){
//							obd="JOBD, EOBD, and OBD II";
//						}else if((Readbuf[3]&0xFF)==0x0E){
//							obd="OBD, EOBD and KOBD";
//						}else if((Readbuf[3]&0xFF)==0x0F){
//							obd="OBD, OBD II, EOBD and KOBD";
//						}else if((Readbuf[3]&0xFF)==0x10){
//							obd="SAE/ISO reserved";
//						}else if((Readbuf[3]&0xFF)==0x11){
//							obd="EMD";
//						}else if((Readbuf[3]&0xFF)==0x12){
//							obd="EMD+";
//						}else if((Readbuf[3]&0xFF)==0x13){
//							obd="HD OBD-C";
//						}else if((Readbuf[3]&0xFF)==0x14){
//							obd="HD OBD";
//						}else if((Readbuf[3]&0xFF)==0x15){
//							obd="WWH OBD";
//						}else if((Readbuf[3]&0xFF)==0x16){
//							obd="SAE/ISO reserved";
//						}else if((Readbuf[3]&0xFF)==0x17){
//							obd="HD EOBD-I";
//						}else if((Readbuf[3]&0xFF)==0x18){
//							obd="HD EOBD-I N";
//						}else if((Readbuf[3]&0xFF)==0x19){
//							obd="HD EOBD-II";
//						}else if((Readbuf[3]&0xFF)==0x1A){
//							obd="HD EOBD-II N";
//						}else if((Readbuf[3]&0xFF)==0x1B){
//							obd="SAE/ISO reserved";
//						}else if((Readbuf[3]&0xFF)==0x1C){
//							obd="OBDBr-1";
//						}else if((Readbuf[3]&0xFF)==0x1D){
//							obd="OBDBr-2";
//						}else if((Readbuf[3]&0xFF)==0x1E){
//							obd="KOBD";
//						}else if((Readbuf[3]&0xFF)==0x1F){
//							obd="IOBD I";
//						}else if((Readbuf[3]&0xFF)==0x20){
//							obd="IOBD II";
//						}else if((Readbuf[3]&0xFF)==0x21){
//							obd="HD EOBD-VI";
//						}else if((Readbuf[3]&0xFF)==0x22){
//							obd="OBD, OBD II and HD OBD";
//						}else if((Readbuf[3]&0xFF)==0x23){
//							obd="OBDBr-3";
//						}else if((Readbuf[3]&0xFF)==0x24){
//							obd="MC EOBD-I";
//						}else if((Readbuf[3]&0xFF)==0x25){
//							obd="MC EOBD-II";
//						}else if((Readbuf[3]&0xFF)==0x26){
//							obd="MC COBD-I";
//						}else if((Readbuf[3]&0xFF)==0x27){
//							obd="MC TOBD-I";
//						}else if((Readbuf[3]&0xFF)==0x28){
//							obd="MC JOBD-I";
//						}else if((Readbuf[3]&0xFF)==0x29){
//							obd="CN-OBD-6";
//						}else if((Readbuf[3]&0xFF)==0x2A){
//							obd="OBDBr-D";
//						}else if((Readbuf[3]&0xFF)>0x2A&&(Readbuf[3]&0xFF)<0xFA){
//							obd="ISO/SAE reserved";
//						}else{
//							obd="SAE J1939 special meaning";
//						}
                        obd = String.valueOf(Readbuf[3] & 0xFF);
                        ShowProcessList(step_id, step_name, obd, Common.Rok);
                    } else if (i == 3) {
                        int result = (Readbuf[3] & 0xFF) * 0x1000000 + (Readbuf[4] & 0xFF) * 0x10000 + (Readbuf[5] & 0xFF) * 0x100 + (Readbuf[6] & 0xFF);
                        if (result % 10 == 0) {
                            odo = result / 10 + "KM";
                        } else {
                            odo = ((float) result / 10) + "KM";
                        }
                        ShowProcessList(step_id, step_name, odo, Common.Rok);
                    } else if (i == 4 || i == 7) {//读取ECU名称
                        byte[] res = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, res, 0, res.length);
                        if (i == 4) {
                            ecuName = new String(res);
                        }
                        ShowProcessList(step_id, step_name, new String(res), Common.Rok);
                    } else if (i == 5 || i == 8) {//读取CAL ID
                        for (int j = 0; j < Readbuf[3]; j++) {
                            byte[] id = new byte[16];
                            System.arraycopy(Readbuf, 4 + 16 * j, id, 0, id.length);
                            if (i == 5) {
                                if (j == 0) {
                                    ems_calId1 = new String(id);
                                } else if (j == 1) {
                                    ems_calId2 = new String(id);
                                } else if (j == 2) {
                                    ems_calId3 = new String(id);
                                }
                            }
                            ShowProcessList(step_id, step_name, new String(id), Common.Rok);
                        }
                    } else if (i == 6 || i == 9) {//读取CVN
                        for (int j = 0; j < Readbuf[3]; j++) {
                            byte[] id = new byte[4];
                            System.arraycopy(Readbuf, 4 + 4 * j, id, 0, id.length);
                            if (i == 6) {
                                if (j == 0) {
                                    ems_cvn1 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                } else if (j == 1) {
                                    ems_cvn2 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                } else if (j == 2) {
                                    ems_cvn3 = Commonfunc.bytesToHexStringP(id, 0, id.length);
                                }
                            }
                            ShowProcessList(step_id, step_name, Commonfunc.bytesToHexStringP(id, 0, id.length), Common.Rok);
                        }
                    }
                }
            }
            if (vinError) {//读出来的和扫描的不一致就不上传
//				ShowProcessList(step_id,"上传OBD信息","上传失败",Common.Rnok);
                return;
            }
            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            String param = "<root><vin>" + vin + "</vin><Type>01</Type><Result>ok</Result><OBDDataDetail><O_Module_Name><obd_VIN>" +
                    vin + "</obd_VIN><obd>" + obd + "</obd><odo>" + odo + "</odo><moduleID>7E0/7E8</moduleID><ECUname>" +
                    ecuName + "</ECUname><calID_01>" + ems_calId1 + "</calID_01><calID_02>" + ems_calId2 + "</calID_02><calID_03>" +
                    ems_calId3 + "</calID_03><cvn_01>" + ems_cvn1 + "</cvn_01><cvn_02>" + ems_cvn2 + "</cvn_02><cvn_03>" +
                    ems_cvn3 + "</cvn_03></O_Module_Name><opass>1</opass><otestdate>" + date + "</otestdate><O_created_author>" + Common.cartype.box_serialnum + "</O_created_author>" +
                    "<O_CarManuf>SWC-CB</O_CarManuf><O_Operation>OBD</O_Operation><O_Operator>test</O_Operator></OBDDataDetail></root>";
            byte[] nul = {0};//替换00乱码
            if (param.contains(new String(nul))) {
                param = param.replace(new String(nul), "");
            }
            String result = HttpRequest.uploadOBDToMes(param);
            if (result != null && result.contains("成功")) {
                ShowProcessList(step_id, "上传OBD信息", "上传成功", Common.Rok);
            } else {
//				ShowProcessList(step_id,"上传OBD信息","上传失败",Common.Rnok);
            }
        }

        private void fun_CX62_FlashFront(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            String step_id = null;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            String bootHardVer;
            String bootSoftVer = null;
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))) return;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                step_id = section.get("T" + i + "_ID");
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////

                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(step_id, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(step_id, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    if (i == 1) {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        bootSoftVer = new String(vin);
                        ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                    } else if (i == 2) {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        bootHardVer = new String(vin);
                        if (bootHardVer.equals(bootSoftVer)) {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(step_id, step_name, new String(vin), Common.Rnok);
                        }
                    } else {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(step_id, step_name, new String(vin), Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62_Flash(Profile.Section section, String name) {
            int num = Integer.valueOf(section.get("NUM"));
/*			String step_id = null;
			String step_t = null;
			String step_name = null;
			byte [] Readbuf = new byte[256];
			byte [] seed = new byte[8];
			byte [] key = new byte[8];
			byte [] checkCode= new byte[2];
			int error = 0;
			int n=0;//一次刷写多少个字节
			int flashLens = 0;//刷写字节数
			boolean eraseMemoery=false;
			//获取刷写文件  文件刷写顺序 FlashDriver  / APP /CAL
			String path=Common.Dir+"/BIN/F01R0ADN7D.hex";//6DCT
			if("EMS刷写_MT_SPA0".equals(name)){
				path=Common.Dir+"/BIN/F01R0ADJ9D.hex";
			}else if("EMS刷写_MT_PEPS0".equals(name)){
				path=Common.Dir+"/BIN/F01R0ADJ9C.hex";
			}else if("EMS刷写_AT_SPA0".equals(name)){
				path=Common.Dir+"/BIN/F01R0ADK0X.hex";
			}else if("EMS刷写_AT_PEPS0".equals(name)){
				path=Common.Dir+"/BIN/F01R0ADK0W.hex";
			}

			byte[] bytes =new byte[5000000];
			ArrayList<Integer> sizes=new ArrayList<Integer>();
			Commonfunc.getTextFromHex(path, bytes,new ArrayList<Long>(),sizes);
			if(sizes.size()==0){//空文件
				ShowFuncTip("请检查刷写文件是否存在或文件名称格式是否正确");
				Sleep(3000);
				return;
			}
			byte[] bytes1=new byte[0x4000];//地址0000C000,大小0x4000;
			byte[] bytes2=new byte[0x160000];//地址00020000,大小0x160000;
			System.arraycopy(bytes,0xC000,bytes1,0,bytes1.length);
			System.arraycopy(bytes,0x20000,bytes2,0,bytes2.length);
			if(!SetCanInitial_Flash(Common.cartype.cartype,"EMS2")) {return;}
			for(int i = 1; i < (num + 1); i ++){
				step_t = section.get("T" + i);
				step_id = section.get("T" + i + "_ID");
				step_name = section.get("T" + i + "_NAME");
				if(step_t.length() < 3) continue;
				if(step_t.substring(0, 3).equals("CMD")){  //cmd
					int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
					byte [] cmd = new byte[cmdlen+1];
					if(Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen+1) != cmd.length) return;
					if(i==5){
						if(!SetCanInitial_Flash(Common.cartype.cartype,"EMS1")) {return;}
					}else if(i==7){
						EolFunction.Chery_IMMO_safekey(seed, key,0);
						System.arraycopy(key, 0, cmd, 3,8);
					}else if(i==23){//校验码
						EolFunction.CalcCRC(bytes1,bytes1.length,checkCode);
						System.arraycopy(checkCode,0, cmd, 13, 2);
					}else if(i==26){//校验码
						EolFunction.CalcCRC(bytes2,bytes2.length,checkCode);
						System.arraycopy(checkCode,0, cmd, 13, 2);
					}else if(i==29){//校验码
						byte[] bytes_all=new byte[0x164000];
						System.arraycopy(bytes1,0,bytes_all,0,0x4000);
						System.arraycopy(bytes2,0,bytes_all,0x4000,0x160000);
						EolFunction.CalcCRC(bytes,flashLens,checkCode);
						System.arraycopy(checkCode,0, cmd, 5, 2);
					}
					if(i==18||i==21){ //刷写发送多帧特殊处理
						byte[]flashByte;
						if(i==18){
							flashByte=bytes1;
						}else{
							flashByte=bytes2;
						}
						flashLens=0;
						int len=flashByte.length;
						int sendNum=len/(n-2);
						int last=len%(n-2);
						if(last!=0) sendNum++;
						for(int k=0;k<sendNum;k++){
							if(k%2==0){
								byte[] cm={0x02,0x3E,(byte) 0x80};
								m_com.CanSendOneOnly(0x7DF,cm,3);
							}
							if(k==sendNum-1&&last!=0){
								cmd = new byte[3+last];
								cmd[0]=(byte) ((last+2)&0xFF);
								m_com.x=(byte)((last>>8)&0xFF);
								System.arraycopy(flashByte,flashLens,cmd,3,last);
								flashLens+=last;
							}else{
								cmd = new byte[n+1];
								cmd[0]=(byte) (n&0xFF);
								m_com.x=(byte) ((n>>8)&0xFF);
								System.arraycopy(flashByte,flashLens,cmd,3,n-2);
								flashLens+=(n-2);
							}
							cmd[1]=0x36;
							cmd[2]=(byte)((k+1)&0xFF);

							error=m_com.CanSendAndRecvN2N_Flash(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);

							if(error == 5001){ //通讯超时
								ShowProcessList(step_id,step_name,"通讯超时",Common.Rnok);
								return ;
							}else if(error > 0){//其他负响应
								ShowProcessList(step_id,step_name,Commonfunc.bytesToHexString(Readbuf, 1,Readbuf[0] + 1),Common.Rnok);
								break;
							}
							ShowFuncTip("文件下载中...\n进度"+(flashLens*100/len)+"%");
						}
					}
					//					else if(i==1||i==2||i==3){
					//						m_com.CanSendOneOnly(0x7DF,cmd,cmd.length);
					//					}
					else if(i==14){//普通发送命令
						error =m_com.CanSendAndRecvN2N_LongTime(cmd, cmd.length, Readbuf, Readbuf.length,
								1,15000);
					}else{//普通发送命令
						error =m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length,
								1,Common.cmdmaxtime);
					}

					if(error == 5001){
						ShowProcessList(step_id,step_name,"通讯超时",Common.Rnok);
						return;
					}else if(error>0){
						ShowProcessList(step_id,step_name,Commonfunc.bytesToHexString(Readbuf, 1,Readbuf[0] + 1),Common.Rnok);
						continue;
					}
					Readbuf[0]=30;
					//特殊处理返回结果
					if(i == 6){ //读seed
						System.arraycopy(Readbuf, 3, seed, 0, 8);
					}else if(i==12||i==15){
						byte[] cm={0x02,0x3E,(byte) 0x80};
						m_com.CanSendOneOnly(0x7DF,cm,3);
						if(Readbuf[5]==2){
							ShowProcessList(step_id, step_name,"擦除成功", Common.Rok);
						}else if(Readbuf[5]==3){
							if(!eraseMemoery){
								ShowProcessList(step_id, step_name,"擦除中...", Common.Rok);
								eraseMemoery=true;
							}
							Sleep(1000);
							i--;
						}else {
							ShowProcessList(step_id, step_name,"擦除失败", Common.Rnok);
							return;
						}
					}else if(i==17||i==20){
						//						n=128;
						if(Readbuf[2]>>4==4){//四个字节
							n=((Readbuf[5]&0xFF)*0x100)+((Readbuf[6]&0xFF));
						}else if(Readbuf[2]>>4==3){//三个字节
							n=(Readbuf[4]&0xFF)*0x100+(Readbuf[5]&0xFF);
						}else if(Readbuf[2]>>4==2){//二个字节
							n=(Readbuf[3]&0xFF)*0x100+(Readbuf[4]&0xFF);
						}else if(Readbuf[2]>>4==1){//一个字节
							n=Readbuf[3]&0xFF;
						}
						ShowProcessList(step_id, step_name,"", Common.Rok);
					}else if(i==24||i==27||i==30){
						if(Readbuf[5]==2){
							ShowProcessList(step_id, step_name,"校验成功", Common.Rok);
						}else if(Readbuf[5]==3){
							if(!eraseMemoery){
								ShowProcessList(step_id, step_name,"校验除中...", Common.Rok);
								eraseMemoery=true;
							}
							Sleep(100);
							i--;
						}else {
							ShowProcessList(step_id, step_name,"校验失败", Common.Rnok);
							return;
						}
					}else{
						ShowProcessList(step_id, step_name,"", Common.Rok);
					}
				}
			}
*/
        }

        private void fun_CX62_Flash_com(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
/*			String step_id = null;
			String step_t = null;
			String step_name = null;
			byte [] Readbuf = new byte[256];
			byte [] seed = new byte[8];
			byte [] key = new byte[8];
			byte [] checkCode= new byte[2];
			int error = 0;
			int n=0;//一次刷写多少个字节
			int duan=0;//几段刷写
			int flashLens = 0;//刷写字节数
			int fileLens=0; //当前文件总字节数
			//获取刷写文件  文件刷写顺序 FlashDriver  / APP /CAL
			String path=Common.Dir+"/BIN/";

			byte[] bytesDriver =new byte[5000000];
			ArrayList<Long> startAddsDriver=new ArrayList<Long>();
			ArrayList<Integer> sizesDriver=new ArrayList<Integer>();
			Commonfunc.getTextFromHex(path+"flashdriver.hex", bytesDriver, startAddsDriver, sizesDriver);

			byte[] bytes =new byte[5000000];
			ArrayList<Long> startAdds=new ArrayList<Long>();
			ArrayList<Integer> sizes=new ArrayList<Integer>();

			if(!SetCanInitial_Flash(Common.cartype.cartype,section.get("MODULE"))) {return;}
			for(int i = 0; i < (num + 1); i ++){
				step_t = section.get("T" + i);
				step_id = section.get("T" + i + "_ID");
				step_name = section.get("T" + i + "_NAME");
				if(step_t.length() < 3) continue;
				if(step_t.substring(0, 3).equals("CMD")){  //cmd
					int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
					byte [] cmd = new byte[cmdlen+1];
					if(Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen+1) != cmd.length) return;
					if(i==6){
						EolFunction.Chery_IMMO_safekey(seed, key,0);
						System.arraycopy(key, 0, cmd, 3,8);
					}else if(i==7){
						for(int k=0;k<sizesDriver.size();k++){
							fileLens+=sizesDriver.get(k);
						}
						System.arraycopy(Commonfunc.IntTobytes(startAddsDriver.get(duan)),0, cmd, 4, 4);
						System.arraycopy(Commonfunc.IntTobytes(sizesDriver.get(duan)),0, cmd, 8, 4);
					}else if(i==10){
						duan=0;//刷写第二个文件
						for(int k=0;k<sizes.size();k++){
							fileLens+=sizes.get(k);
						}
						System.arraycopy(Commonfunc.IntTobytes(startAdds.get(0)),0, cmd, 5, 4);
						long clearSize=startAdds.get(startAdds.size()-1)+
								sizes.get(sizes.size()-1)-startAdds.get(0);
						System.arraycopy(Commonfunc.IntTobytes(clearSize),0, cmd, 9, 4);
					}else if(i==11){
						duan=0;//刷写第二个文件
						for(int k=0;k<sizes.size();k++){
							fileLens+=sizes.get(k);
						}
						System.arraycopy(Commonfunc.IntTobytes(startAdds.get(duan)),0, cmd, 4, 4);
						System.arraycopy(Commonfunc.IntTobytes(sizes.get(duan)),0, cmd, 8, 4);
					}else if(i==14){//校验码
						EolFunction.CalcCRC(bytes,flashLens,checkCode);
						System.arraycopy(checkCode,0, cmd, 5, 2);
					}else if(i==15){//校验码
						EolFunction.CalcCRC(bytes,flashLens,checkCode);
						System.arraycopy(checkCode,0, cmd, 5, 2);
					}
					if(i==8||i==12){ //刷写发送多帧特殊处理
						byte[]flashByte;
						int len;
						if(i==8){
							flashByte=bytesDriver;
							len=sizesDriver.get(duan);
						}else{
							flashByte=bytes;
							len=sizes.get(duan);
						}
						int sendNum=len/(n-2);
						int last=len%(n-2);
						if(last!=0) sendNum++;
						for(int k=0;k<sendNum;k++){
							if(k==sendNum-1&&last!=0){
								cmd = new byte[3+last];
								cmd[0]=(byte) ((last+2)&0xFF);
								m_com.x=(byte)((last>>8)&0xFF);
								System.arraycopy(flashByte,flashLens,cmd,3,last);
								flashLens+=last;
							}else{
								cmd = new byte[n+1];
								cmd[0]=(byte) (n&0xFF);
								m_com.x=(byte) ((n>>8)&0xFF);
								System.arraycopy(flashByte,flashLens,cmd,3,n-2);
								flashLens+=(n-2);
							}
							cmd[1]=0x36;
							cmd[2]=(byte)((k+1)&0xFF);

							error=m_com.CanSendAndRecvN2N_Flash(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);

							if(error == 5001){ //通讯超时
								ShowProcessList(step_id,step_name,"通讯超时",Common.Rnok);
								return ;
							}else if(error > 0){//其他负响应
								ShowProcessList(step_id,step_name,Commonfunc.bytesToHexString(Readbuf, 1,Readbuf[0] + 1),Common.Rnok);
								break;
							}
							if(i==8){
								ShowFuncTip("驱动文件下载中...\n进度"+(flashLens*100/fileLens)+"%");
							}else if(i==12){
								ShowFuncTip("文件下载中...\n进度"+(flashLens*100/fileLens)+"%");
							}
						}
					}else if(i==14){//普通发送命令
						error =m_com.CanSendAndRecvN2N_LongTime(cmd, cmd.length, Readbuf, Readbuf.length,
								1,15000);
					}else{//普通发送命令
						error =m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length,
								1,Common.cmdmaxtime);
					}

					if(error == 5001){
						ShowProcessList(step_id,step_name,"通讯超时",Common.Rnok);
						return;
					}else if(error>0){
						ShowProcessList(step_id,step_name,Commonfunc.bytesToHexString(Readbuf, 1,Readbuf[0] + 1),Common.Rnok);
						return;
					}
					Readbuf[0]=30;
					//特殊处理返回结果
					if(i == 0){ //零件号
						byte[] partNumber=new byte[(Readbuf[0]&0xFF)-3];
						System.arraycopy(Readbuf, 3,partNumber, 0, partNumber.length);
						ShowProcessList(step_id, step_name,new String(partNumber), Common.Rok);
						if("F01-3605010".equals(new String(partNumber))){
							path+="F01R0ADJ9C.hex";
						}else if("F01-3605010AE".equals(partNumber)){
							path+="F01R0ADJ9D.hex";
						}else if("F01-3605010AF".equals(partNumber)){
							path+="F01R0ADK0X.hex";
						}else if("F01-3605010AB".equals(partNumber)){
							path+="F01R0ADK0W.hex";
						}else{
							path+="F01R0ADN7D.hex";
						}
						Commonfunc.getTextFromHex(path, bytes, startAdds, sizes);
						if(startAdds.size()==0){//空文件
							ShowFuncTip("请检查刷写文件是否存在或文件名称格式是否正确");
							Sleep(3000);
							return;
						}
					}else if(i == 5){ //读seed
						System.arraycopy(Readbuf, 3, seed, 0, 8);
					}else if(i==7||i==11){
						//						n=128;
						if(Readbuf[2]>>4==4){//四个字节
							n=((Readbuf[5]&0xFF)*0x100)+((Readbuf[6]&0xFF));
						}else if(Readbuf[2]>>4==3){//三个字节
							n=(Readbuf[4]&0xFF)*0x100+(Readbuf[5]&0xFF);
						}else if(Readbuf[2]>>4==2){//二个字节
							n=(Readbuf[3]&0xFF)*0x100+(Readbuf[4]&0xFF);
						}else if(Readbuf[2]>>4==1){//一个字节
							n=Readbuf[3]&0xFF;
						}
						ShowProcessList(step_id, step_name,"", Common.Rok);
					}else if(i==9){
						if(duan<startAddsDriver.size()-1){//开始刷写下一段
							duan++;
							i=6;//刷下一段
						}
					}else if(i==13){
						if(duan<startAdds.size()-1){//开始刷写下一段
							duan++;
							i=10;//刷下一段
						}
					}else if(i==16){
						Sleep(2000);
					}else{
						ShowProcessList(step_id, step_name,"", Common.Rok);
					}
				}
			}
*/
        }


        ///////////////////////CX62B////////////////////////////
        private void fun_CX62B_IMMO1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            byte[] v_escl_status = new byte[10];    //ESCL状态
            byte[] v_immo_status = new byte[10];    //IMMO状态
            byte[] v_ems_status = new byte[10];    //EMS状态
            byte[] v_trans_status = new byte[10];    //转发器状态
            String status;
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            byte[] cmd_link = {0x02, 0x3E, (byte) 0x80};
            int key_retry = Integer.valueOf(section.get("KEY_RETRY"));
            int key_wait = Integer.valueOf(section.get("KEY_WAIT"));
            int[] canid = new int[2];
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) > cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    //复位重试次数
                    if (i == 43 || i == 52)
                        key_retry = Integer.valueOf(section.get("KEY_RETRY"));
                    //设置CAN
                    if (i == 1 || i == 9 || i == 34 || i == 43 || i == 64)//IMMO
                    {
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1", canid)) return;
                    } else if (i == 23 || i == 40) //切换至EMS
                    {
                        if (!SetCanInitial(Common.cartype.cartype, "EMS1", canid)) return;
                    } else if (i == 2 || i == 61 || i == 69)//切换至PEPS
                    {
                        if (i == 61) //判断执行ESCL
                        {
                            if (Common.cartype.getMap("TCU") > 0)
                                break;
                        }
                        if (!SetCanInitial(Common.cartype.cartype, "PEPS1", canid)) return;
                    }
                    //条件
                    if (i == 5) //PEPS sa3
                    {
                        if ((seed[0] | seed[1]) == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 13 || i == 26)//安全认证1
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 18 || i == 32 || i == 36 || i == 46 || i == 55 || i == 66)//安全认证2
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3] | seed[4] | seed[5] | seed[6] | seed[7]) == 0)
                            continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) //config
                    {
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, (cmd[0] & 0xFF) - 3);
                    } else if (i == 14 || i == 27) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 15)//IMMO写PIN
                    {
                        if ((v_immo_status[1] & 0x04) == 0x04) continue;
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 28) { //EMS写PIN
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 19 || i == 20 || i == 21 || i == 47 || i == 48 || i == 49)//第1把钥匙
                    {
                        //判断
                        if (((v_trans_status[0] >> 5) & 0x01) == 1) //已关联
                        {
                            i += 3;
                            continue;
                        } else if (((v_trans_status[0] >> 3) & 0x01) == 1)//旧钥匙未关联
                        {
                            cmd[4] = 0x01;
                        }
                        //Common.wait = true;
                        //m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100,"将第一把车钥匙置于杯托有<钥匙>标识处，第一把钥匙置于距离此处 50cm外").sendToTarget();
                        //while(Common.wait) //发链路
                        //{
                        //	Sleep(1000);
                        //	m_com.CanSendOneOnly(0x74D, cmd_link, cmd_link[0] + 1);
                        //}
                    } else if (i == 43)//提示更换第二把钥匙
                    {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100, getResources().getString(R.string.second_key_distance_first_key)).sendToTarget();
                        while (Common.wait) //发链路
                        {
                            Sleep(100);
                        }
                    } else if (i == 52) //提示更换第3把钥匙
                    {
                        if (true) {//没有BM则不学习第三把钥匙
                            i += 8;
                            continue;
                        }
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100, getResources().getString(R.string.third_key_distance_first_key)).sendToTarget();
                        while (Common.wait) //发链路
                        {
                            Sleep(100);
                        }
                    } else if (i == 8 || i == 20 || i == 48 || i == 57 || i == 68) {
                        Sleep(3000);
                    }

                    if (i == 19 || i == 33 || i == 37 || i == 47 || i == 56 || i == 67)
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    else
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    String t_step = String.valueOf(Pid); //显示测试结果
                    if (i == 71)//key on,后等待10秒
                    {
                        if (((Readbuf[4] >> 0) & 0x01) == 0x01)//ON
                        {
                            for (int k = 10; k > 0; k--) {
                                ShowFuncTip("key on  等待" + k + "秒");
                                Sleep(1000);
                            }
                        } else {
                            i--;
                            Sleep(500);
                        }
                    } else if (i == 62) //key off
                    {
                        if (((Readbuf[4] >> 0) & 0x01) == 0x00)//off
                        {
                        } else {
                            i--;
                            Sleep(500);
                        }
                    } else if (i == 4 || i == 12 || i == 17 || i == 25 || i == 31 || i == 35 || i == 45 || i == 54 || i == 65) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 10) //读IMMO状态
                    {
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[1]) != 0) {
                            ShowProcessList(t_step, step_name, "IMMO已学过", Common.Rok);
                        }
                        if (((v_immo_status[1] >> 1) & 0x01) == 0x01) //VIN已写
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_immo_status[1] >> 2) & 0x01) == 0x01) //VIN已写
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        int nu = (v_immo_status[1] >> 3) & 0x07;
                        status += "KEY:" + nu;
                        ShowProcessList(t_step, step_name, status, Common.Rok);
                    } else if (i == 11 || i == 44 || i == 50 || i == 58)//读转发器状态
                    {
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        int Result = 1;
                        if ((v_trans_status[0] & 0x01) == 0x01) //防盗线圈故障
                            status = "Ring:1;";
                        else {
                            status = "Ring:0;";
                            Result = 2;
                        }
                        if (((v_trans_status[0] >> 3) & 0x01) == 0x01) //new
                            status += "New:0;";
                        else
                            status += "New:1;";
                        if (((v_trans_status[0] >> 4) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(t_step, step_name, status, Result);

                    } else if (i == 8) //config
                    {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                        if (iRet == 2) break;
                    } else if (i == 16 || i == 29) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                    } else if (i == 20 || i == 38 || i == 48 || i == 57 || i == 68) { //15检查钥匙学习结果,33检查EMS学习SK情况,45key2,63tcu,68 immo teach tcu,77immo teach escl
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03)//继续
                        {
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(Pid, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(Pid, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(Pid, step_name, "Routine failure and routine not run!", Common.Rnok);
                            i = 69;
                            continue;
                        }
                    } else if (i == 22 || i == 50) { //检查转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        if ((v_trans_status[0] & 0x20) == 0x20) //已经配对
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        else {
                            ShowProcessList(Pid, step_name, Readbuf[5] + "", Common.Rnok);
                        }
                    } else if (i == 24 || i == 41) { //读取EMS状态
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x01) == 0x01) //VIN
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_ems_status[1] >> 2) & 0x01) == 0x01) //PIN
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        if (((v_ems_status[1] >> 3) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        if (i == 24) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                i = 41;
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                                continue;
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnull);
                        } else if (i == 41) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnok);
                        }
                    } else if (i == 60) { //检查钥匙数量
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        int keynum = (v_immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        boolean v_isc = false;
                        //if(Common.cartype.getMap("BM")>0)
                        v_isc = false;
                        byte isok = 1;
                        if (v_isc) {
                            if (keynum != 3)
                                isok = 0;
                        } else {
                            if (keynum != 2)
                                isok = 0;
                        }
                        ShowProcessList(Pid, step_name, keynum + "把", 2 - isok);
                    } else if (i == 63)//ESCL学习结果
                    {
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x00) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL已经学习过!", Common.Rok);
                            i += 6;
                            continue;
                        } else
                            ShowProcessList(t_step, step_name, "ESCL开始学习!", Common.Rok);
                    } else if (i == 69) {//ESCL学习结果
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x01) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL认证失败!", Common.Rnok);
                        } else
                            ShowProcessList(t_step, step_name, "ESCL OK!", Common.Rok);
                    } else {
                        ShowProcessList(t_step, step_name, "", Common.Rok);
                    }
                } else if (step_t.substring(0, 3).equals("SHW")) { //SHW
                    int v_add1 = step_t.indexOf("<");
                    int v_add2 = step_t.indexOf(">");
                    if (Common.Debug) Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                    String v_data1 = step_t.substring(4, v_add1);
                    int v_time = Integer.valueOf(step_t.substring(v_add1 + 1, v_add2));
                    if (v_data1.equals("NO") == true) { //直接显示文本内容
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) { //发链路
                            byte[] cmd = new byte[]{0x02, 0x3E, 0x00};
                            error = m_com.CanSendOneOnly(canid[0], cmd, cmd.length);
                            //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                            Sleep(2000);
                        }
                    }
                }
            }
        }

        private void fun_JX65_IMMO1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            byte[] v_escl_status = new byte[10];    //ESCL状态
            byte[] v_immo_status = new byte[10];    //IMMO状态
            byte[] v_ems_status = new byte[10];    //EMS状态
            byte[] v_trans_status = new byte[10];    //转发器状态
            String status;
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            byte[] cmd_link = {0x02, 0x3E, (byte) 0x00};
            int key_retry = Integer.valueOf(section.get("KEY_RETRY"));
            int key_wait = Integer.valueOf(section.get("KEY_WAIT"));
            int[] canid = new int[2];
            m_com.m_log.PrintAppend(0, "GetPin:" + Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) > cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    //复位重试次数
                    if (i == 43 || i == 52)
                        key_retry = Integer.valueOf(section.get("KEY_RETRY"));
                    //设置CAN
                    if (i == 1 || i == 9 || i == 34 || i == 43 || i == 64)//IMMO
                    {
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1", canid)) return;
                    } else if (i == 23 || i == 40) //切换至EMS
                    {
                        if (!SetCanInitial(Common.cartype.cartype, "EMS1", canid)) return;
                    } else if (i == 2 || i == 61 || i == 69)//切换至PEPS
                    {
                        if (i == 61) //判断执行ESCL
                        {
                            if (Common.cartype.getMap("TCU") > 0)
                                break;
                        }
                        if (!SetCanInitial(Common.cartype.cartype, "PEPS1", canid)) return;
                    }
                    //条件
                    if (i == 5) //PEPS sa3
                    {
                        if ((seed[0] | seed[1]) == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04)//安全认证1
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x06)//安全认证2
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3] | seed[4] | seed[5] | seed[6] | seed[7]) == 0)
                            continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) //config
                    {
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, (cmd[0] & 0xFF) - 3);
                    } else if (i == 14 || i == 27) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 15)//IMMO写PIN
                    {
                        if ((v_immo_status[1] & 0x04) == 0x04) continue;
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 28) { //EMS写PIN
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 19 || i == 20 || i == 21 || i == 47 || i == 48 || i == 49)//第1把钥匙
                    {
                        //判断
                        if (((v_trans_status[0] >> 5) & 0x01) == 1) //已关联
                        {
                            i += 3;
                            continue;
                        } else if (((v_trans_status[0] >> 3) & 0x01) == 1)//旧钥匙未关联
                        {
                            cmd[4] = 0x01;
                        }
                        //Common.wait = true;
                        //m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100,"将第一把车钥匙置于杯托有<钥匙>标识处，第一把钥匙置于距离此处 50cm外").sendToTarget();
                        //while(Common.wait) //发链路
                        //{
                        //	Sleep(1000);
                        //	m_com.CanSendOneOnly(0x74D, cmd_link, cmd_link[0] + 1);
                        //}
                    } else if (i == 43)//提示更换第二把钥匙
                    {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100, getResources().getString(R.string.second_key_distance_first_key)).sendToTarget();
                        while (Common.wait) //发链路
                        {
                            Sleep(100);
                        }
                    } else if (i == 52) //提示更换第3把钥匙
                    {
                        if (true) {//没有BM则不学习第三把钥匙
                            i += 8;
                            continue;
                        }
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100, getResources().getString(R.string.third_key_distance_first_key)).sendToTarget();
                        while (Common.wait) //发链路
                        {
                            Sleep(100);
                        }
                    } else if (i == 8 || i == 20 || i == 48 || i == 57 || i == 68) {
                        Sleep(3000);
                    }
                    //添加link
                    if (i > 24 && i < 33) {
                        error = m_com.CanSendOneOnly(canid[0], cmd_link, cmd_link.length);
                        //m_com.CanSendAndRecvN2N(cmd_link, cmd_link.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                        Sleep(100);
                    }

                    if (i == 19 || i == 33 || i == 37 || i == 47 || i == 56 || i == 67)
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    else
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    String t_step = String.valueOf(Pid); //显示测试结果
                    if (i == 71)//key on,后等待10秒
                    {
                        if (((Readbuf[4] >> 0) & 0x01) == 0x01)//ON
                        {
                            for (int k = 10; k > 0; k--) {
                                ShowFuncTip("key on  等待" + k + "秒");
                                Sleep(1000);
                            }
                        } else {
                            i--;
                            Sleep(500);
                        }
                    } else if (i == 62) //key off
                    {
                        if (((Readbuf[4] >> 0) & 0x01) == 0x00)//off
                        {
                        } else {
                            i--;
                            Sleep(500);
                        }
                    } else if (Readbuf[1] == 0x67 && ((Readbuf[2] == 0x3) || (Readbuf[2] == 0x5) || (Readbuf[2] == 0x7))) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 10) //读IMMO状态
                    {
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[1]) != 0) {
                            ShowProcessList(t_step, step_name, "IMMO已学过", Common.Rok);
                        }
                        if (((v_immo_status[1] >> 1) & 0x01) == 0x01) //VIN已写
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_immo_status[1] >> 2) & 0x01) == 0x01) //VIN已写
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        int nu = (v_immo_status[1] >> 3) & 0x07;
                        status += "KEY:" + nu;
                        if (((v_immo_status[1] & 0x06) == 0x06) && nu == 2) {
                            ShowProcessList(t_step, step_name, status, Common.Rok);
                            //return;
                        } else
                            ShowProcessList(t_step, step_name, status, Common.Rok);
                    } else if (i == 11 || i == 44 || i == 50 || i == 58)//读转发器状态
                    {
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        int Result = 1;
                        if ((v_trans_status[0] & 0x01) == 0x01) //防盗线圈故障
                            status = "Ring:1;";
                        else {
                            status = "Ring:0;";
                            Result = 2;
                        }
                        if (((v_trans_status[0] >> 3) & 0x01) == 0x01) //new
                            status += "New:0;";
                        else
                            status += "New:1;";
                        if (((v_trans_status[0] >> 4) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(t_step, step_name, status, Result);
                        if (i == 44) {
                            if (((v_trans_status[0] >> 4) & 0x01) == 0x01)  //钥匙已经关联
                            {
                                Common.wait = true;
                                m_handler.obtainMessage(Message.MSG_Dialog_SHow_YESNO, 0, 100, getResources().getString(R.string.key_bound_want_continue)).sendToTarget();
                                while (Common.wait) //发链路
                                {
                                    m_com.CanSendOneOnly(0x74D, cmd_link, cmd_link[0] + 1);
                                    Sleep(1000);
                                }
                                if (Common.dialog_result == false) //否
                                {
                                    i = 43;
                                    continue;
                                }
                            }
                        }
                    } else if (i == 8) //config
                    {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                        if (iRet == 2) break;
                    } else if (i == 16 || i == 29) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                    } else if (i == 20 || i == 38 || i == 48 || i == 57 || i == 68) { //15检查钥匙学习结果,33检查EMS学习SK情况,45key2,63tcu,68 immo teach tcu,77immo teach escl
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03)//继续
                        {
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(Pid, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(Pid, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(Pid, step_name, "Routine failure and routine not run!", Common.Rnok);
                            i = 69;
                            continue;
                        }
                    } else if (i == 22 || i == 50) { //检查转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        if ((v_trans_status[0] & 0x20) == 0x20) //已经配对
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        else {
                            ShowProcessList(Pid, step_name, Readbuf[5] + "", Common.Rnok);
                        }
                    } else if (i == 24 || i == 41) { //读取EMS状态
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x01) == 0x01) //VIN
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_ems_status[1] >> 2) & 0x01) == 0x01) //PIN
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        if (((v_ems_status[1] >> 3) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        if (i == 24) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                i = 41;
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                                continue;
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnull);
                        } else if (i == 41) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnok);
                        }
                    } else if (i == 60) { //检查钥匙数量
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        int keynum = (v_immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        boolean v_isc = false;
                        //if(Common.cartype.getMap("BM")>0)
                        v_isc = false;
                        byte isok = 1;
                        if (v_isc) {
                            if (keynum != 3)
                                isok = 0;
                        } else {
                            if (keynum != 2)
                                isok = 0;
                        }
                        ShowProcessList(Pid, step_name, keynum + "把", 2 - isok);
                    } else if (i == 63)//ESCL学习结果
                    {
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x00) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL已经学习过!", Common.Rok);
                            i += 6;
                            continue;
                        } else
                            ShowProcessList(t_step, step_name, "ESCL开始学习!", Common.Rok);
                    } else if (i == 69) {//ESCL学习结果
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x01) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL认证失败!", Common.Rnok);
                        } else
                            ShowProcessList(t_step, step_name, "ESCL OK!", Common.Rok);
                    } else {
                        ShowProcessList(t_step, step_name, "", Common.Rok);
                    }
                } else if (step_t.substring(0, 3).equals("SHW")) { //SHW
                    int v_add1 = step_t.indexOf("<");
                    int v_add2 = step_t.indexOf(">");
                    if (Common.Debug) Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                    String v_data1 = step_t.substring(4, v_add1);
                    int v_time = Integer.valueOf(step_t.substring(v_add1 + 1, v_add2));
                    if (v_data1.equals("NO") == true) { //直接显示文本内容
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) { //发链路
                            byte[] cmd = new byte[]{0x02, 0x3E, 0x00};
                            error = m_com.CanSendOneOnly(canid[0], cmd, cmd.length);
                            //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                            Sleep(2000);
                        }
                    }
                }
            }
        }

        private void fun_JX65PHEV_IMMO1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            byte[] v_escl_status = new byte[10];    //ESCL状态
            byte[] v_immo_status = new byte[10];    //IMMO状态
            byte[] v_ems_status = new byte[10];    //EMS状态
            byte[] v_trans_status = new byte[10];    //转发器状态
            String status;
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            byte[] cmd_link = {0x02, 0x3E, (byte) 0x00};
            int key_retry = Integer.valueOf(section.get("KEY_RETRY"));
            int key_wait = Integer.valueOf(section.get("KEY_WAIT"));
            int[] canid = new int[2];
            m_com.m_log.PrintAppend(0, "GetPin:" + Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) > cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    //复位重试次数
                    if (i == 43 || i == 52)
                        key_retry = Integer.valueOf(section.get("KEY_RETRY"));
                    //设置CAN
                    if (i == 1 || i == 9 || i == 34 || i == 43 || i == 64)//IMMO
                    {
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1", canid)) return;
                    } else if (i == 23 || i == 40) //切换至EMS
                    {
                        if (!SetCanInitial(Common.cartype.cartype, "HCU1", canid)) return;
                    } else if (i == 2 || i == 61 || i == 69)//切换至PEPS
                    {
                        if (i == 61) //判断执行ESCL
                        {
                            if (Common.cartype.getMap("TCU") > 0)
                                break;
                        }
                        if (!SetCanInitial(Common.cartype.cartype, "PEPS1", canid)) return;
                    }
                    //条件
                    if (i == 5) //PEPS sa3
                    {
                        if ((seed[0] | seed[1]) == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04)//安全认证1
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x06)//安全认证2
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3] | seed[4] | seed[5] | seed[6] | seed[7]) == 0)
                            continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) //config
                    {
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, (cmd[0] & 0xFF) - 3);
                    } else if (i == 14 || i == 27) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 15)//IMMO写PIN
                    {
                        if ((v_immo_status[1] & 0x04) == 0x04) continue;
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 28) { //EMS写PIN
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 19 || i == 20 || i == 21 || i == 47 || i == 48 || i == 49)//第1把钥匙
                    {
                        //判断
                        if (((v_trans_status[0] >> 5) & 0x01) == 1) //已关联
                        {
                            i += 3;
                            continue;
                        } else if (((v_trans_status[0] >> 3) & 0x01) == 1)//旧钥匙未关联
                        {
                            cmd[4] = 0x01;
                        }
                        //Common.wait = true;
                        //m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100,"将第一把车钥匙置于杯托有<钥匙>标识处，第一把钥匙置于距离此处 50cm外").sendToTarget();
                        //while(Common.wait) //发链路
                        //{
                        //	Sleep(1000);
                        //	m_com.CanSendOneOnly(0x74D, cmd_link, cmd_link[0] + 1);
                        //}
                    } else if (i == 43)//提示更换第二把钥匙
                    {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100, getResources().getString(R.string.second_key_distance_first_key)).sendToTarget();
                        while (Common.wait) //发链路
                        {
                            Sleep(100);
                        }
                    } else if (i == 52) //提示更换第3把钥匙
                    {
                        if (true) {//没有BM则不学习第三把钥匙
                            i += 8;
                            continue;
                        }
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100, getResources().getString(R.string.third_key_distance_first_key)).sendToTarget();
                        while (Common.wait) //发链路
                        {
                            Sleep(100);
                        }
                    } else if (i == 8 || i == 20 || i == 48 || i == 57 || i == 68) {
                        Sleep(3000);
                    }
                    //添加link
                    if (i > 24 && i < 33) {
                        error = m_com.CanSendOneOnly(canid[0], cmd_link, cmd_link.length);
                        //m_com.CanSendAndRecvN2N(cmd_link, cmd_link.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                        Sleep(100);
                    }

                    if (i == 19 || i == 33 || i == 37 || i == 47 || i == 56 || i == 67)
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    else
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    String t_step = String.valueOf(Pid); //显示测试结果
                    if (i == 71)//key on,后等待10秒
                    {
                        if (((Readbuf[4] >> 0) & 0x01) == 0x01)//ON
                        {
                            for (int k = 10; k > 0; k--) {
                                ShowFuncTip("key on  等待" + k + "秒");
                                Sleep(1000);
                            }
                        } else {
                            i--;
                            Sleep(500);
                        }
                    } else if (i == 62) //key off
                    {
                        if (((Readbuf[4] >> 0) & 0x01) == 0x00)//off
                        {
                        } else {
                            i--;
                            Sleep(500);
                        }
                    } else if (Readbuf[1] == 0x67 && ((Readbuf[2] == 0x3) || (Readbuf[2] == 0x5) || (Readbuf[2] == 0x7))) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 10) //读IMMO状态
                    {
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[1]) != 0) {
                            ShowProcessList(t_step, step_name, "IMMO已学过", Common.Rok);
                        }
                        if (((v_immo_status[1] >> 1) & 0x01) == 0x01) //VIN已写
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_immo_status[1] >> 2) & 0x01) == 0x01) //VIN已写
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        int nu = (v_immo_status[1] >> 3) & 0x07;
                        status += "KEY:" + nu;
                        if (((v_immo_status[1] & 0x06) == 0x06) && nu == 2) {
                            ShowProcessList(t_step, step_name, status, Common.Rok);
                            //return;
                        } else
                            ShowProcessList(t_step, step_name, status, Common.Rok);
                    } else if (i == 11 || i == 44 || i == 50 || i == 58)//读转发器状态
                    {
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        int Result = 1;
                        if ((v_trans_status[0] & 0x01) == 0x01) //防盗线圈故障
                            status = "Ring:1;";
                        else {
                            status = "Ring:0;";
                            Result = 2;
                        }
                        if (((v_trans_status[0] >> 3) & 0x01) == 0x01) //new
                            status += "New:0;";
                        else
                            status += "New:1;";
                        if (((v_trans_status[0] >> 4) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(t_step, step_name, status, Result);
                        if (i == 44) {
                            if (((v_trans_status[0] >> 4) & 0x01) == 0x01)  //钥匙已经关联
                            {
                                Common.wait = true;
                                m_handler.obtainMessage(Message.MSG_Dialog_SHow_YESNO, 0, 100, getResources().getString(R.string.key_bound_want_continue)).sendToTarget();
                                while (Common.wait) //发链路
                                {
                                    Sleep(500);
                                    m_com.CanSendOneOnly(0x74D, cmd_link, cmd_link[0] + 1);
                                }
                                if (Common.dialog_result == false) //否
                                {
                                    i = 43;
                                    continue;
                                }
                            }
                        }
                    } else if (i == 8) //config
                    {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                        if (iRet == 2) break;
                    } else if (i == 16 || i == 29) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                    } else if (i == 20 || i == 38 || i == 48 || i == 57 || i == 68) { //15检查钥匙学习结果,33检查EMS学习SK情况,45key2,63tcu,68 immo teach tcu,77immo teach escl
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03)//继续
                        {
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(Pid, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(Pid, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(Pid, step_name, "Routine failure and routine not run!", Common.Rnok);
                            i = 69;
                            continue;
                        }
                    } else if (i == 22 || i == 50) { //检查转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        if ((v_trans_status[0] & 0x20) == 0x20) //已经配对
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        else {
                            ShowProcessList(Pid, step_name, Readbuf[5] + "", Common.Rnok);
                        }
                    } else if (i == 24 || i == 41) { //读取EMS状态
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x01) == 0x01) //VIN
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_ems_status[1] >> 2) & 0x01) == 0x01) //PIN
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        if (((v_ems_status[1] >> 3) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        if (i == 24) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                i = 41;
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                                continue;
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnull);
                        } else if (i == 41) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnok);
                        }
                    } else if (i == 60) { //检查钥匙数量
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        int keynum = (v_immo_status[1] >> 3) & 0x07; //关联的钥匙数量
                        boolean v_isc = false;
                        //if(Common.cartype.getMap("BM")>0)
                        v_isc = false;
                        byte isok = 1;
                        if (v_isc) {
                            if (keynum != 3)
                                isok = 0;
                        } else {
                            if (keynum != 2)
                                isok = 0;
                        }
                        ShowProcessList(Pid, step_name, keynum + "把", 2 - isok);
                    } else if (i == 63)//ESCL学习结果
                    {
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x00) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL已经学习过!", Common.Rok);
                            i += 6;
                            continue;
                        } else
                            ShowProcessList(t_step, step_name, "ESCL开始学习!", Common.Rok);
                    } else if (i == 69) {//ESCL学习结果
                        System.arraycopy(Readbuf, 4, v_escl_status, 0, 1);
                        if (v_escl_status[0] != 0x01) { //不OK
                            ShowProcessList(t_step, step_name, "ESCL认证失败!", Common.Rnok);
                        } else
                            ShowProcessList(t_step, step_name, "ESCL OK!", Common.Rok);
                    } else {
                        ShowProcessList(t_step, step_name, "", Common.Rok);
                    }
                } else if (step_t.substring(0, 3).equals("SHW")) { //SHW
                    int v_add1 = step_t.indexOf("<");
                    int v_add2 = step_t.indexOf(">");
                    if (Common.Debug) Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                    String v_data1 = step_t.substring(4, v_add1);
                    int v_time = Integer.valueOf(step_t.substring(v_add1 + 1, v_add2));
                    if (v_data1.equals("NO") == true) { //直接显示文本内容
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) { //发链路
                            byte[] cmd = new byte[]{0x02, 0x3E, 0x00};
                            error = m_com.CanSendOneOnly(canid[0], cmd, cmd.length);
                            //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                            Sleep(2000);
                        }
                    }
                }
            }
        }

        private void fun_CX62B_EMS1(Profile.Section section) {
            //can初始化
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))) return;
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[8];
            byte[] key = new byte[8];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) {//安全认证
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) { //写vin
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) {//通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error > 0) {//其他负响应
                        if ((i == 8) && (Readbuf[3] == 0x22)) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                            continue;
                        } else if (error < 100) //异常回复
                        {
                            if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                            {
                                if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                    ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                                else
                                    ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                                continue;
                            }
                        }

                    }
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 8);
                    } else if (i == 5) {//读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                            i += 2;
                        }
                    } else if (i == 7) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        if (new String(vin).equals(new String(Common.cartype.vin))) {
                            ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, new String(vin), Common.Rnok);
                        }
                    } else if (i == 8) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_ESP1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.S32EV_ABS_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    } else if (i == 5) { //写配置
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, 0x20);
                    } else if (i == 6) { //写配置
                        if (Common.cartype.getMap("EPB_D") == 0) continue;
                        System.arraycopy(Common.cartype.getMapByte("ESP"), 0, cmd, 4, 1);
                    } else if (i == 10) {
                        if (Common.cartype.getMap("EPB_D") == 0) continue;
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 5) {
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 0, (cmd[0] & 0xFF) - 3), Common.Rok);
                    } else if (i == 7) { //复位
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 8) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                    } else if (i == 9) { //读配置
                        if (Readbuf[4] == 1) {
                            ShowProcessList(Pid, step_name, "加注成功", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "加注失败", Common.Rnok);
                        }
                    } else if (i == 10) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.getMapByte("ESP"));
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        //EPS/ICM/plg/cgw/fipm/cem/
        private void fun_CX62B_standconfig1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4)//安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        if (section.get("MODULE").equals("BDM1"))
                            EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        else if (section.get("MODULE").equals("EPB1"))
                            EolFunction.Cx62B_EPB_Safekey(seed, key);
                        else
                            EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 5) { //写配置
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, cmd[0] - 3);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 5) {
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 0, (cmd[0] & 0xFF) - 3), Common.Rok);
                        Sleep(500);
                    } else if (i == 6) { //复位
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 7) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        //fcm/frm/dvr/fws/GSM/ABM
        private void fun_CX62B_standVIN1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        if (section.get("MODULE").equals("FCM1"))
                            EolFunction.Cx62B_FCM_Level1(seed, key, 0x29D6);
                        else if (section.get("MODULE").equals("FRM1"))
                            EolFunction.Cx62B_FCM_Level2(seed, key, 0x5600);
                        else if (section.get("MODULE").equals("ABM1")) {
                            if (cmd[0] == 0x04)
                                EolFunction.M1AEV_2018_IMMO_safekey(seed, key);
                            else
                                EolFunction.CX62B_ABM_seedToKey(seed, key, 0x36583001);
                        } else
                            EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 5) //VIN
                    {
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3)//读seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 5) {
                        ShowProcessList(Pid, step_name, new String(Common.cartype.vin), Common.Rok);
                    } else if (i == 6)//复位
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 7)//读vin
                    {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.vin);
                        ShowProcessList(Pid, step_name, new String(vin), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        //rrm/tbox
        private void fun_CX62B_standVINAndConfig1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 5)//写配置
                    {
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, cmd[0] - 3);
                    } else if (i == 6) //VIN
                    {
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3)//读seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 5) {
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 0, (cmd[0] & 0xFF) - 3), Common.Rok);
                    } else if (i == 6) {
                        ShowProcessList(Pid, step_name, new String(Common.cartype.vin), Common.Rok);
                    } else if (i == 7) { //复位
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else if (i == 8) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                    } else if (i == 9)//读vin
                    {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.vin);
                        ShowProcessList(Pid, step_name, new String(vin), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_APM2(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, cmd[0] - 3);
                    } else if (i == 7) {
                        ShowFuncTip("正在学习防夹...");
                    } else if (i == 9) {
                        Sleep(2000);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 6) {
                        Sleep(2000); //延时一下。
                    } else if (i == 8) { //复位
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (i == 9) { //读配置
                        if (Readbuf[5] == 3) { //运行
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 5) { //error
                            ShowProcessList(Pid, step_name, ("程序失败或程序没有运行"), Common.Rnok);
                            i++;
                        } else if (Readbuf[5] == 2) { //ok
                            ShowProcessList(Pid, step_name, ("执行完成"), Common.Rok);
                            //玻璃升降结果
                            if ((Readbuf[6] & 0x01) == 0x01)
                                ShowProcessList(Pid, step_name, "左前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "左前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x02) == 0x02)
                                ShowProcessList(Pid, step_name, "右前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "右前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x04) == 0x04)
                                ShowProcessList(Pid, step_name, "左后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "左后玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x08) == 0x08)
                                ShowProcessList(Pid, step_name, "右后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "右后玻璃:初始化失败", Common.Rok);
                        }
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_ClearAllDtc(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            String module = "";
            int[] canid = new int[2];
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    module = step_name.substring(0, step_name.indexOf("-"));
                    int select = Common.cartype.getMap(module);
                    if (select < 1) //不存在
                    {
                        continue;
                    }
                    //can初始化
                    if (!SetCanInitial(Common.cartype.cartype, module + select, canid)) {
                        return;
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + "--NOK");
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    //特殊处理返回结果
                    ShowProcessList(Pid, step_name, "", Common.Rok);
                }
            }
        }

        private void fun_CX62B_ReadAllDtc(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            int[] canid = new int[2];
            String module = "";
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    module = step_name.substring(0, step_name.indexOf("-"));
                    int select = Common.cartype.getMap(module);
                    if (select < 1) //不存在
                    {
                        continue;
                    }
                    //can初始化
                    if (!SetCanInitial(Common.cartype.cartype, module + select, canid)) {
                        return;
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + "--NOK");
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    //特殊处理返回结果
                    byte[] dtc = new byte[128];
                    ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                    dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                    System.arraycopy(Readbuf, 4, dtc, 1, (dtc[0] & 0xFF) * 4);
                    GetDtcArray(module + select, dtc, dtclist, 3);
                    if (dtclist.size() > 0) {
                        if (dtclist.size() <= 4) {
                            for (int z = 0; z < dtclist.size(); z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(Pid, step_name, dtclist.get(z).get("NAME") + "-" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                        } else {
                            for (int z = 0; z < 4; z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(Pid, step_name, dtclist.get(z).get("NAME") + "-" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                            clearOrReadDtc.add(module.substring(0, module.length() - 1) + ":" + t_dtc);
                            t_dtc = "";
                            for (int z = 4; z < dtclist.size(); z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(Pid, step_name, dtclist.get(z).get("NAME") + "--" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                        }
                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + ":" + t_dtc);
                    }
                }
            }
        }

        private void fun_CX62B_ReadConfig(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            String module = "";
            int[] canid = new int[2];
            for (int i = 1; i <= num; i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    module = step_name.substring(0, step_name.indexOf("-"));
                    int select = Common.cartype.getMap(module);
                    if (select < 1) //不存在
                    {
                        continue;
                    }
                    //can初始化
                    if (!SetCanInitial(Common.cartype.cartype, module + select, canid)) {
                        return;
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + "--NOK");
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    //特殊处理返回结果
                    byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                    System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                    int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                    ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);

                }
            }
        }

        private void fun_CX62B_ReadVerInfo(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            String module = "";
            int[] canid = new int[2];
            for (int i = 1; i <= num; i++) {

                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                ShowFuncTip(step_name + "...");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    //这里先判断是否存在该模块
                    if ((i % 3) == 1) {
                        module = step_name.substring(0, step_name.indexOf("-"));
                        int select = Common.cartype.getMap(module);
                        if (select < 1) //不存在
                        {
                            i += 2;
                            continue;
                        }
                        //can初始化
                        if (!SetCanInitial(Common.cartype.cartype, module + select, canid)) {
                            return;
                        }
                        Sleep(Common.waittime);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        clearOrReadDtc.add(module.substring(0, module.length() - 1) + "--NOK");
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //String t_step = String.valueOf(Integer.valueOf(step_id) + 1); //显示测试结果，序号+1
                    //特殊处理返回结果
                    int v_len = 1;
                    if (Readbuf[0] > 3)
                        v_len = Readbuf[0] - 3;
                    if ((i % 3) == 1) //零件号
                    {
                        byte[] ver = new byte[v_len];
                        System.arraycopy(Readbuf, 4, ver, 0, v_len);
                        String s_ver = new String(ver);
                        s_ver = s_ver.replace(" ", "");
                        s_ver = s_ver.trim();
                        List<String> mes_sn = CommonXml.GetEcuInfoSn(Common.cartype.mesinfo, module, s_ver);
                        if (mes_sn != null) {
                            if (Common.cartype.mesinfo.getEcuId() >= 0)
                                ShowProcessList(Pid, step_name, s_ver, Common.Rok);
                            else {
                                String v_showdata = "MES:";
                                if (mes_sn != null && mes_sn.size() > 0) {
                                    v_showdata += mes_sn.get(0);
                                    for (int k = 1; k < mes_sn.size(); k++)
                                        v_showdata += "," + mes_sn.get(k);
                                }
                                ShowProcessList(Pid, step_name, s_ver + "\n" + v_showdata, Common.Rnok);
                            }
                        } else
                            ShowProcessList(Pid, step_name, new String(ver), Common.Rnull);
                    } else if ((i % 3) == 2) //软件版本
                    {
                        byte[] ver = new byte[v_len];
                        System.arraycopy(Readbuf, 4, ver, 0, v_len);
                        String s_ver = new String(ver);
                        s_ver = s_ver.replace(" ", "");
                        s_ver = s_ver.trim();
                        String v_soft = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, module);
                        //String v_soft2 = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, module,0,1);
                        //String v_soft1 = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, null,0);
                        //String v_soft2 = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, null,1);
                        if (v_soft != null) {
                            int isfind = v_soft.indexOf(s_ver);
                            if (isfind >= 0) //ok
                                ShowProcessList(Pid, step_name, s_ver, Common.Rok);
                            else {
                                String v_data = "Mes:";
                                v_data += v_soft;
                                ShowProcessList(Pid, step_name, s_ver + "\n" + v_data, Common.Rnok);
                            }
                        } else
                            ShowProcessList(Pid, step_name, s_ver, Common.Rnull);
                    } else //硬件版本
                    {
                        byte[] ver = new byte[v_len];
                        System.arraycopy(Readbuf, 4, ver, 0, v_len);
                        String s_ver = new String(ver);
                        s_ver = s_ver.replace(" ", "");
                        s_ver = s_ver.trim();
                        String v_hard = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, module);
                        //String v_hard2 = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, module,0,1);
                        if (v_hard != null) {
                            int isfind = v_hard.indexOf(s_ver);
                            if (isfind >= 0) //ok
                                ShowProcessList(Pid, step_name, s_ver, Common.Rok);
                            else {
                                String v_data = "Mes:";
                                v_data += v_hard;
                                ShowProcessList(Pid, step_name, s_ver + "\n" + v_data, Common.Rnok);
                            }
                        } else
                            ShowProcessList(Pid, step_name, s_ver, Common.Rnull);
                    }
                }
            }
        }

        private void fun_CX62B_EPS1_Cal(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] _corner = new byte[2];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) {
                        System.arraycopy(_corner, 0, cmd, 5, 2);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 1) {
                        short corner = (short) (Readbuf[4] * 0x100 + (Readbuf[5] & 0xFF));
                        short cor = (short) (0 - corner);
                        _corner[0] = (byte) ((cor >> 8) & 0xFF);
                        _corner[1] = (byte) (cor & 0xFF);
                        ShowProcessList(Pid, step_name, String.valueOf(corner), Common.Rok);
                    } else if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 5) {
                        if (Readbuf[5] == 0) {
                            ShowProcessList(Pid, step_name, "标定", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "未标定", Common.Rok);
                        }
                        Sleep(2000);
                    } else if (i == 6) {
                        int result = (Readbuf[4] * 0x100 + (Readbuf[5] & 0xFF));
                        if (result <= 3 && result >= -3) {
                            ShowProcessList(Pid, step_name, "合格", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "不合格", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_APM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            int repeart_time = 3;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4 || i == 9) { //安全认证
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5) { //写配置
                        System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, cmd[0] - 3);
                    } else if (i == 12) {
                        ShowFuncTip("正在学习防夹...");
                    } else if (i == 7) //复位后等待
                    {
                        Sleep(2000);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3 || i == 8) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 11) //学习延时
                    {
                        Sleep(2500); //延时一下。
                    } else if (i == 6) { //复位
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (i == 12) //学习结果
                    {
                        if (Readbuf[5] == 3) { //运行
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 5) { //error
                            if (repeart_time > 0) {
                                ShowProcessList(Pid, step_name, "学习失败,重学第" + (4 - repeart_time) + "次!", Common.Rnull);
                                repeart_time--;
                                i = 1;
                                continue;
                            } else {
                                ShowProcessList(Pid, step_name, "程序失败或程序没有运行", Common.Rnok);
                                i++;
                            }
                        } else if (Readbuf[5] == 2) { //ok
                            ShowProcessList(Pid, step_name, "执行完成", Common.Rok);
                            //玻璃升降结果
                            if ((Readbuf[6] & 0x01) == 0x01)
                                ShowProcessList(Pid, step_name, "左前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "左前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x02) == 0x02)
                                ShowProcessList(Pid, step_name, "右前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "右前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x04) == 0x04)
                                ShowProcessList(Pid, step_name, "左后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "左后玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x08) == 0x08)
                                ShowProcessList(Pid, step_name, "右后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "右后玻璃:初始化失败", Common.Rok);
                        }
                    } else if (i == 10) { //读配置
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.configbyte);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, (Readbuf[0] & 0xFF) - 3), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_KX63A_APM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) {
                        ShowFuncTip("正在学习防夹...");
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 5) { //复位
                        if (Readbuf[5] == 1) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "错误码:%02X", Common.Rok);
                            break;
                        }
                    } else if (i == 6) { //读配置
                        if (Readbuf[5] == 3) { //运行
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 5) { //error
                            ShowProcessList(Pid, step_name, ("程序失败或程序没有运行"), Common.Rnok);
                            i++;
                        } else if (Readbuf[5] == 2) { //ok
                            ShowProcessList(Pid, step_name, ("执行完成"), Common.Rok);
                            //玻璃升降结果
                            if ((Readbuf[6] & 0x01) == 0x01)
                                ShowProcessList(Pid, step_name, "左前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "左前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x02) == 0x02)
                                ShowProcessList(Pid, step_name, "右前玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "右前玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x04) == 0x04)
                                ShowProcessList(Pid, step_name, "左后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "左后玻璃:初始化失败", Common.Rok);
                            if ((Readbuf[6] & 0x08) == 0x08)
                                ShowProcessList(Pid, step_name, "右后玻璃:初始化完成", Common.Rok);
                            else
                                ShowProcessList(Pid, step_name, "右后玻璃:初始化失败", Common.Rok);
                        }
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_EPB1_Cal(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.Chery_CX62_EPB_SafeKey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 5) {
                        if (Readbuf[5] == 0xC0) {
                            ShowProcessList(Pid, step_name, "标定", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "未标定", Common.Rok);
                        }
                        Sleep(2000);
                    } else if (i == 6) {
                        if (Readbuf[4] == 1) {
                            ShowProcessList(Pid, step_name, "合格", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "不合格", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_ESP1_Cal(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.S32EV_ABS_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 4);
                    } else if (i == 5) {
                        if (Readbuf[5] == 2) {
                            ShowProcessList(Pid, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "未标定", Common.Rok);
                        }
                    } else if (i == 6) {
                        if (Readbuf[5] == 3) {
                            ShowProcessList(Pid, step_name, "标定中...", Common.Rok);
                            Sleep(1000);
                            i--;
                        } else if (Readbuf[5] == 2) {
                            ShowProcessList(Pid, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "标定失败", Common.Rok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_ABM_Cal(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (cmd[1] == 0x27 && cmd[2] == 0x04) { //安全认证
                        byte seedcal = 0;
                        for (int kk = 0; kk < cmd[0] - 2; kk++) {
                            seedcal |= seed[kk];
                        }
                        if (seedcal == 0) continue;
                        EolFunction.Chery_JX65_Safekey(seed, key, section.get("MODULE"));
                        System.arraycopy(key, 0, cmd, 3, (cmd[0] & 0xFF) - 2);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (cmd[1] == 0x27 && cmd[2] == 0x03) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    }
                    if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, (Readbuf[0] & 0xFF) - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                        }
                        if (v_code == 0x181D) {
                            if (Readbuf[4] == 0x02) {
                                ShowProcessList(Pid, step_name, "标定成功", Common.Rok);
                                break;
                            }
                        }
                    } else if (Readbuf[1] == 0x71) {
                        if (Readbuf[2] == 0x01) {
                            if (Readbuf[5] == 0x01)
                                ShowProcessList(Pid, step_name, "", Common.Rok);
                            else {
                                ShowProcessList(Pid, step_name, "Code:" + (Readbuf[5] & 0xFF) + "," + (Readbuf[6] & 0xFF), Common.Rnok);
                            }
                        } else if (Readbuf[2] == 0x02) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else if (Readbuf[2] == 0x03) {
                            if (Readbuf[5] == 0x04)
                                ShowProcessList(Pid, step_name, "", Common.Rok);
                            else if (Readbuf[5] == 0x03) {
                                i--;
                                Sleep(1000);
                                continue;
                            } else {
                                ShowProcessList(Pid, step_name, "Code:" + (Readbuf[5] & 0xFF) + "," + (Readbuf[6] & 0xFF), Common.Rnok);
                            }
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_SAM1_Cal(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int[] v_canid = new int[2];
            boolean isinit = false;
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                Pid = Pidfirst + i;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 1 || i == 4) {
                        SetCanInitial(Common.cartype.cartype, "SAM2", v_canid);
                    } else if (i == 2) {
                        SetCanInitial(Common.cartype.cartype, "SAM1", v_canid);
                    } else if (i == 3) {
                        if (isinit) {
                            SetCanInitial(Common.cartype.cartype, "SAM1", v_canid);
                            Sleep(100);
                        }
                    }
                    ///////////////////////命令发送////////////////////////////////
                    if (i == -1) {
                    } else //普通发送命令
                    {
                        error = m_com.CanSendAndRecvO2O_Spec(v_canid[0], v_canid[1], cmd, cmd.length, Readbuf, Readbuf.length, 1, Common.cmdmaxtime);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 1) { //判断SAM状态
                        if (Readbuf[4] != 0) {
                            ShowProcessList(Pid, step_name, "SAS错误!", Common.Rnok);
                            break;
                        } else if ((Readbuf[3] & 0x04) != 0x04) { //未标定
                            i++;
                            isinit = true;
                            ShowProcessList(Pid, step_name, "SAM未标定", Common.Rok);
                        } else
                            ShowProcessList(Pid, step_name, "SAM已标定", Common.Rok);
                    } else if (i == 2) { //
                        ShowProcessList(Pid, step_name, "SAS未标定", Common.Rok);
                        Sleep(1000);
                    } else if (i == 3) {
                        ShowProcessList(Pid, step_name, "SAM执行成功", Common.Rok);
                        Sleep(1000);
                    } else if (i == 4) {
                        if ((Readbuf[3] & 0x04) != 0x04) { //未标定
                            ShowProcessList(Pid, step_name, "SAM标定失败", Common.Rnok);
                        } else {
                            ShowProcessList(Pid, step_name, "SAM标定成功", Common.Rok);
                        }
                    }
                } else if (step_t.substring(0, 3).equals("SHW")) { //SHW
                    int v_add1 = step_t.indexOf("<");
                    int v_add2 = step_t.indexOf(">");
                    if (Common.Debug) Log.i(TAG, "v_add1 = " + v_add1 + "; v_add2 = " + v_add2);
                    String v_data1 = step_t.substring(4, v_add1);
                    int v_time = Integer.valueOf(step_t.substring(v_add1 + 1, v_add2));
                    if (v_data1.equals("ON") == true) {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 1).sendToTarget();
                        while (Common.wait) {
                            Sleep(Common.waittime);
                        }
                        ;
                    } else if (v_data1.equals("OFF") == true) {
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 2).sendToTarget();
                        while (Common.wait) {
                            Sleep(Common.waittime);
                        }
                        ;
                    } else if (v_data1.equals("NO") == true) { //直接显示文本内容
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) { //发链路
                            byte[] cmd = new byte[]{0x02, 0x3E, 0x00};
                            error = m_com.CanSendOneOnly(v_canid[0], cmd, cmd.length);
                            //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                            Sleep(1500);
                        }
                    } else if (v_data1.equals("NOLINK") == true) { //直接显示文本内容没有链路
                        Common.wait = true;
                        m_handler.obtainMessage(Message.MSG_Dialog_WaitTime, v_time, 3, step_name).sendToTarget();
                        while (Common.wait) {
                            Sleep(Common.waittime);
                        }
                        ; //
                    }
                }
            }
        }

        private void fun_CX62B_GBC1_Cal(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] config = new byte[128];
            int error = 0;
            int[] canid = new int[2];
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 1) {
                        if (!SetCanInitial(Common.cartype.cartype, "TCU1", canid)) return;

                    } else if (i == 3) {
                        if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid))
                            return;

                    } else if (i == 5) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.hongyuan_SDM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 6) {
                        System.arraycopy(config, 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    if (i == 7)
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 10);
                    else
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 2) {
                        System.arraycopy(Readbuf, 4, config, 0, 8);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(config, 0, 8), Common.Rok);
                    } else if (i == 4) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 7) {
                        if (Readbuf[5] == 3) {
                            ShowProcessList(Pid, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "标定失败", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_GBC1_Cal(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] config = new byte[128];
            int[] canid = new int[2];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 1) {
                        if (!SetCanInitial(Common.cartype.cartype, "TCU1", canid)) return;

                    } else if (i == 3) {
                        if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid))
                            return;

                    } else if (i == 5) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 6) {
                        System.arraycopy(config, 0, cmd, 4, 8);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    if (i == 7)
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 10, 2);
                        //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 10);
                    else
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 2) {
                        System.arraycopy(Readbuf, 4, config, 0, 8);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(config, 0, 8), Common.Rok);
                    } else if (i == 4) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 7) {
                        if (Readbuf[5] == 3) {
                            ShowProcessList(Pid, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "标定失败", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_IMMO_Addkey(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            byte[] config = new byte[128];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            m_com.m_log.PrintAppend("Pin:" + Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
            String status;
            byte[] v_immo_status = new byte[10];    //IMMO状态
            byte[] v_trans_status = new byte[10];    //转发器状态
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    cmdlen += 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 5)//安全认证1
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 10)//安全认证2
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3] | seed[4] | seed[5] | seed[6] | seed[7]) == 0)
                            continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 6) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 7)//IMMO写PIN
                    {
                        if ((v_immo_status[1] & 0x04) == 0x04) continue;
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    } else if (i == 11 || i == 12 || i == 13)//第1把钥匙
                    {
                        //判断
                        if (((v_trans_status[0] >> 5) & 0x01) == 1) //已关联
                        {
                            i += 3;
                            continue;
                        } else if (((v_trans_status[0] >> 3) & 0x01) == 1)//旧钥匙未关联
                        {
                            cmd[4] = 0x01;
                        }
                        //Common.wait = true;
                        //m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, key_wait, 100,"将第一把车钥匙置于杯托有<钥匙>标识处，第一把钥匙置于距离此处 50cm外").sendToTarget();
                        //while(Common.wait) //发链路
                        //{
                        //	Sleep(1000);
                        //	m_com.CanSendOneOnly(0x74D, cmd_link, cmd_link[0] + 1);
                        //}
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime + 2000, 2);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 4 || i == 9) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 2) //读IMMO状态
                    {
                        System.arraycopy(Readbuf, 4, v_immo_status, 0, 4);
                        if ((v_immo_status[1]) != 0) {
                            ShowProcessList(Pid, step_name, "IMMO已学过", Common.Rok);
                        }
                        if (((v_immo_status[1] >> 1) & 0x01) == 0x01) //VIN已写
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_immo_status[1] >> 2) & 0x01) == 0x01) //VIN已写
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        int nu = (v_immo_status[1] >> 3) & 0x07;
                        status += "KEY:" + nu;
                        ShowProcessList(Pid, step_name, status, Common.Rok);
                    } else if (i == 3)//读转发器状态
                    {
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        int Result = 1;
                        if ((v_trans_status[0] & 0x01) == 0x01) //防盗线圈故障
                            status = "Ring:1;";
                        else {
                            status = "Ring:0;";
                            Result = 2;
                        }
                        if (((v_trans_status[0] >> 3) & 0x01) == 0x01) //new
                            status += "New:0;";
                        else
                            status += "New:1;";
                        if (((v_trans_status[0] >> 4) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        ShowProcessList(Pid, step_name, status, Result);

                    } else if (i == 8) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                    } else if (i == 12) {
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03)//继续
                        {
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(Pid, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(Pid, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(Pid, step_name, "Routine failure and routine not run!", Common.Rnok);
                            i = 69;
                            continue;
                        }
                    } else if (i == 14) { //检查转发器状态
                        System.arraycopy(Readbuf, 4, v_trans_status, 0, 4);
                        if ((v_trans_status[0] & 0x20) == 0x20) //已经配对
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        else {
                            ShowProcessList(Pid, step_name, Readbuf[5] + "", Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_IMMO_studyems(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            byte[] config = new byte[128];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            m_com.m_log.PrintAppend("Pin:" + Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
            String status;
            byte[] v_ems_status = new byte[10];    //EMS状态
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    cmdlen += 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 12) {
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1", canid)) {
                            ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                            return;
                        }
                    } else if (i == 18) {
                        if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                            ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                            return;
                        }
                    }
                    if (i == 4)//安全认证1
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 10 || i == 14)//安全认证2
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3] | seed[4] | seed[5] | seed[6] | seed[7]) == 0)
                            continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 5) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 6)//IMMO写PIN
                    {
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    }

                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime + 2000, 2);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3 || i == 9 || i == 13) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 2 || i == 19)//读ems状态
                    {
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x01) == 0x01) //VIN
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_ems_status[1] >> 2) & 0x01) == 0x01) //PIN
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        if (((v_ems_status[1] >> 3) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        if (i == 2) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                i = 19;
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                                continue;
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnull);
                        } else if (i == 19) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnok);
                        }
                    } else if (i == 7) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                    } else if (i == 16) {
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03)//继续
                        {
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(Pid, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(Pid, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(Pid, step_name, "Routine failure and routine not run!", Common.Rnok);
                            i = 69;
                            continue;
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65PHEV_IMMO_studyHCU(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            byte[] config = new byte[128];
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            m_com.m_log.PrintAppend("Pin:" + Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4));
            String status;
            byte[] v_ems_status = new byte[10];    //EMS状态
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    cmdlen += 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 12) {
                        if (!SetCanInitial(Common.cartype.cartype, "IMMO1", canid)) {
                            ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                            return;
                        }
                    } else if (i == 18) {
                        if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                            ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                            return;
                        }
                    }
                    if (i == 4)//安全认证1
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 10 || i == 14)//安全认证2
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3] | seed[4] | seed[5] | seed[6] | seed[7]) == 0)
                            continue;
                        int pin = (Common.cartype.pin[0] & 0xFF) * 0x1000000 + (Common.cartype.pin[1] & 0xFF) * 0x10000 +
                                (Common.cartype.pin[2] & 0xFF) * 0x100 + (Common.cartype.pin[3] & 0xFF) * 0x01;
                        EolFunction.Chery_IMMO_safekey(seed, key, pin);
                        System.arraycopy(key, 0, cmd, 3, 8);
                    } else if (i == 5) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 6)//IMMO写PIN
                    {
                        System.arraycopy(Common.cartype.pin, 0, cmd, 4, 4);
                    }

                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime + 2000, 2);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3 || i == 9 || i == 13) { //获取SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 2 || i == 19)//读ems状态
                    {
                        System.arraycopy(Readbuf, 4, v_ems_status, 0, 4);
                        if (((v_ems_status[1] >> 1) & 0x01) == 0x01) //VIN
                            status = "VIN:1;";
                        else
                            status = "VIN:0;";
                        if (((v_ems_status[1] >> 2) & 0x01) == 0x01) //PIN
                            status += "PIN:1;";
                        else
                            status += "PIN:0;";
                        if (((v_ems_status[1] >> 3) & 0x01) == 0x01) //SK
                            status += "SK:1;";
                        else
                            status += "SK:0;";
                        if (i == 2) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                i = 19;
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                                continue;
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnull);
                        } else if (i == 19) {
                            if (((v_ems_status[1] >> 1) & 0x07) == 0x07) { //EMS已经学习过
                                ShowProcessList(Pid, step_name, status, Common.Rok);
                            } else
                                ShowProcessList(Pid, step_name, status, Common.Rnok);
                        }
                    } else if (i == 7) { //读VIN,显示
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, new String(vin), Common.Rok);
                    } else if (i == 16) {
                        if (Readbuf[5] == 0x01 || Readbuf[5] == 0x03)//继续
                        {
                            Sleep(500);
                            i--;
                        } else if (Readbuf[5] == 0x02) {//OK
                            ShowProcessList(Pid, step_name, "ok", Common.Rok);
                        } else if (Readbuf[5] == 0x04) { //stop
                            ShowProcessList(Pid, step_name, "Routine stopped!", Common.Rnok);
                            break;
                        } else {    //stop
                            ShowProcessList(Pid, step_name, "Routine failure and routine not run!", Common.Rnok);
                            i = 69;
                            continue;
                        }
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_FCM2_Cal(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] config = new byte[128];
            int[] canid = new int[2];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 1) {
                        if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid))
                            return;

                    } else if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 9) //vin
                    {
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, 17);
                    } else if (i == 11) {
                        cmd[39] = (byte) (m_fcm_fh / 0x100);
                        cmd[40] = (byte) (m_fcm_fh % 0x100);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 5 || i == 6 || i == 7) {
                        byte[] ver = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, ver, 0, Readbuf[0] - 3);
                        ShowProcessList(Pid, step_name, new String(ver), Common.Rok);
                    } else if (i == 10) //vin
                    {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.vin);
                        ShowProcessList(Pid, step_name, new String(vin), iRet);
                    } else if (i == 12) {
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(vin, 0, vin.length), Common.Rok);
                    } else if (i == 13) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(2000);
                    } else if (i == 14) {
                        if (Readbuf[5] == 3 || Readbuf[5] == 1) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 2) {
                            ShowProcessList(Pid, step_name, "标定成功", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "标定失败", Common.Rnok);
                        }
                    } else if (i == 16) {
                        byte[] dtc = new byte[128];
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, (dtc[0] & 0xFF) * 4);
                        GetDtcArray(section.get("MODULE"), dtc, dtclist, 3);
                        if (dtclist.size() > 0) {
                            for (int z = 0; z < dtclist.size(); z++) {
                                ShowProcessList(Pid, step_name, dtclist.get(z).get("NAME") + "-" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                        } else
                            ShowProcessList(Pid, step_name, "无故障.", Common.Rok);
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_SEAT1_Cal(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] config = new byte[128];
            int error = 0;
            int[] canid = new int[2];
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 1) {
                        if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid))
                            return;

                    } else if (i == 4) { //安全认证
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 6) {
                        ShowFuncTip("正在进行座椅学习...");
                    }

                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime * 2);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, 2);
                    } else if (i == 5) {
                        if ((Readbuf[5] & 0xFF) == 0xFF)
                            ShowProcessList(Pid, step_name, "正在初始化", Common.Rok);
                        else if ((Readbuf[5] & 0xFF) == 0x01)
                            ShowProcessList(Pid, step_name, "初始化失败", Common.Rnok);
                    } else if (i == 6) {
                        if ((Readbuf[4] & 0xFF) == 0xFF)
                            ShowProcessList(Pid, step_name, "初始化成功", Common.Rok);
                        else if ((Readbuf[4] & 0xFF) == 0x01)
                            ShowProcessList(Pid, step_name, "初始化失败", Common.Rnok);
                        else {
                            i--;
                            Sleep(1000);
                        }

                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_BM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if ((seed[0] | seed[1]) == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 5) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, cmd[0] - 3);
                    } else if (i == 6) //pin
                    {
                        //System.arraycopy(Common.cartype.pin, 0, cmd, 4, cmd[0] - 3);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 6) {
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(Common.cartype.pin, 0, 4), Common.Rok);
                    } else if (i == 7) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.vin);
                        ShowProcessList(Pid, step_name, new String(vin), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_EGSM1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if ((seed[0] | seed[1]) == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 5) { //写VIN
                        System.arraycopy(Common.cartype.vin, 0, cmd, 4, cmd[0] - 3);
                    } else if (i == 6) //pin
                    {
                        //System.arraycopy(Common.cartype.pin, 0, cmd, 4, cmd[0] - 3);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 6) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1500);
                    } else if (i == 8) { //读VIN
                        byte[] vin = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, vin, 0, (Readbuf[0] & 0xFF) - 3);
                        int iRet = 2 - Commonfunc.bytesCompare(vin, Common.cartype.vin);
                        ShowProcessList(Pid, step_name, new String(vin), iRet);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_TCU1(Profile.Section section) {
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE"))){return;}
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4) { //安全认证
                        if (cmd[0] == 4) {
                            if ((seed[0] | seed[1]) == 0) continue;
                            EolFunction.M1AEV_2018_IMMO_safekey(seed, key);
                        } else {
                            if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                            EolFunction.CX62B_7DCT_seedToKey(seed, key);
                        }
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 5) {
                        cmd[4] = (byte) (Common.cartype.configbyte[11] & 0x0F);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    if (i == 3) {    //读seed
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 5) {
                        ShowProcessList(Pid, step_name, Commonfunc.byteToString(cmd[4]), Common.Rok);
                    } else if (i == 7) {
                        if (Readbuf[4] == (Common.cartype.configbyte[11] & 0x0F))
                            ShowProcessList(Pid, step_name, Commonfunc.byteToString(Readbuf[4]), Common.Rok);
                        else
                            ShowProcessList(Pid, step_name, Commonfunc.byteToString(Readbuf[4]), Common.Rnok);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_CX62B_TPMS1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            byte[] config = new byte[128];
            byte[] tpmsid = new byte[4];
            //if(!SetCanInitial(Common.cartype.cartype,section.get("MODULE")))return;
            int error = 0;
            int[] canid = new int[2];
            if (!SetCanInitial(Common.cartype.cartype, section.get("MODULE"), canid)) {
                ShowProcessList(100, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////
                    if (i == 4)//安全认证
                    {
                        if (seed[0] == 0 && seed[1] == 0) continue;
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, 2);
                    } else if (i == 5 || i == 7 || i == 9 || i == 11) //写入TPMS ID
                    {
                        for (int kk = 0; kk < 4; kk++)
                            tpmsid[kk] = (byte) (0x10 + i);
                        System.arraycopy(tpmsid, 0, cmd, 4, 4);
                    }
                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 3) { //复制SEED
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (i == 5 || i == 7 || i == 9 || i == 11) //写
                    {
                        byte[] v_id = new byte[4];
                        System.arraycopy(cmd, 4, v_id, 0, 4);
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexStringP(v_id, 0, 4), Common.Rok);
                    } else if (i == 6 || i == 8 || i == 10 || i == 12) //读ID
                    {
                        String str = Commonfunc.bytesToHexStringP(Readbuf, 4, 8);
                        int xx = (Readbuf[4] | Readbuf[5]) & 0xFF;
                        if (xx == 0 || xx == 0xFF)
                            ShowProcessList(Pid, step_name, str, Common.Rnok);
                        else
                            ShowProcessList(Pid, step_name, str, Common.Rok);
                    } else if (i == 0) //写状态
                    {
                        if (Readbuf[4] == 0)
                            ShowProcessList(Pid, step_name, "未学习", Common.Rnok);
                        else if (Readbuf[4] == 1)
                            ShowProcessList(Pid, step_name, "学习成功", Common.Rok);
                        else
                            ShowProcessList(Pid, step_name, "学习错误", Common.Rnok);

                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        //氢能源电检
        private void fun_qing_Eol_0(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////

                    Sleep(200);

                    ///////////////////////命令发送////////////////////////////////
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    //特殊处理返回结果
                    Random random = new Random();
                    int rand = random.nextInt(10);
                    if (i > 0) {
                        String v_value = "";
                        switch (i) {
                            case 1:
                                v_value = "0 rpm<0rpm>";
                                break;
                            case 2:
                                v_value = "允许给定转矩<-->";
                                break;
                            case 3:
                                v_value = (25 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 4:
                                v_value = (25 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 5:
                                v_value = "无故障<-->";
                                break;
                            case 6:
                                v_value = "断开<-->";
                                break;
                            case 7:
                                v_value = "5<40>";
                                break;
                            case 8:
                                v_value = "2." + (rand % 5) + " MPa<1 ~ 3MPa>";
                                break;
                            case 9:
                                v_value = "0 ppm<0 ~ 500 ppm>";
                                break;
                            case 10:
                                v_value = String.format("%.1f", (26.1 + rand * 0.1)) + " ℃<0 ~ 50℃>";
                                break;
                            case 11:
                                v_value = (rand % 3) + "号<1 ~ 7>";
                                break;
                            case 12:
                                v_value = String.format("%.1f", (24.2 + rand * 0.1)) + " ℃<0 ~ 50℃>";
                                break;
                            case 13:
                                v_value = (3 + (rand % 3)) + "<1 ~ 7>";
                                break;
                            case 14:
                                v_value = "瓶口阀关闭<-->";
                                break;
                            case 15:
                                v_value = "主电磁阀关闭<-->";
                                break;
                            case 16:
                                v_value = "0 MPa<0 MPa>";
                                break;
                            case 17:
                                v_value = (5 + (rand / 2)) + " %<0 ~ 10%>";
                                break;
                            case 18:
                                v_value = (210 + rand) + "<0 ~ 255>";
                                break;
                            case 19:
                                v_value = "无故障<-- >";
                                break;
                            case 20:
                                v_value = "无故障<-->";
                                break;
                            case 21:
                                v_value = "0 kg<0 kg>";
                                break;
                            case 22:
                                v_value = "0 NM<0 NM >";
                                break;
                            case 23:
                                v_value = "0 rpm<0 rpm>";
                                break;
                            case 24:
                                v_value = (25 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 25:
                                v_value = "0 %<0 % >";
                                break;
                            case 26:
                                v_value = "0 %<0 % >";
                                break;
                            case 27:
                                v_value = String.format("%.1f", (1 + (rand * 0.1))) + " A<1 ~ 3 A>";
                                break;
                            case 28:
                                v_value = (25 + (rand % 3)) + " V<24 ~ 28 V >";
                                break;
                            case 29:
                                v_value = "Ready<-->";
                                break;
                            case 30:
                                v_value = "无故障<-->";
                                break;
                            case 31:
                                v_value = "0 A<-->";
                                break;
                            case 32:
                                v_value = "28 ℃<0 ~ 50℃>";
                                break;
                            case 33:
                                v_value = "0 V<0 V >";
                                break;
                            case 34:
                                v_value = (27 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 35:
                                v_value = "非充电模式<-->";
                                break;
                            case 36:
                                v_value = (25 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 37:
                                v_value = (26 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 38:
                                v_value = (27 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 39:
                                v_value = "正常<-->";
                                break;
                            case 40:
                                v_value = "P 档<-->";
                                break;
                            case 41:
                                v_value = "OK<-->";
                                break;
                            default:
                                v_value = "";
                                break;
                        }
                        ShowProcessList(Pid, step_name, v_value, Common.Rok);
                        t_print.add(step_name + " - 合格");
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_qing_Eol_1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////

                    Sleep(200);

                    ///////////////////////命令发送////////////////////////////////
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    //特殊处理返回结果
                    Random random = new Random();
                    int rand = random.nextInt(10);
                    if (i > 0) {
                        String v_value = "";
                        switch (i) {
                            case 1:
                                v_value = (1000 + rand * 2) + " rpm<0 - 3000rpm>";
                                break;
                            case 2:
                                v_value = "允许给定转矩<-->";
                                break;
                            case 3:
                                v_value = (64 + (rand % 4)) + " ℃<0 ~ 140℃>";
                                break;
                            case 4:
                                v_value = (40 + (rand % 3)) + " ℃<0 ~ 90℃>";
                                break;
                            case 5:
                                v_value = "无故障<-->";
                                break;
                            case 6:
                                v_value = "断开<-->";
                                break;
                            case 7:
                                v_value = "5<40>";
                                break;
                            case 8:
                                v_value = (10 + (rand % 5)) + " MPa<2 ~ 20MPa>";
                                break;
                            case 9:
                                v_value = "0 ppm<0 ~ 500 ppm>";
                                break;
                            case 10:
                                v_value = String.format("%.1f", (26.1 + rand * 0.1)) + " ℃<0 ~ 50℃>";
                                break;
                            case 11:
                                v_value = (1 + (rand % 3)) + "号<1 ~ 7>";
                                break;
                            case 12:
                                v_value = String.format("%.1f", (25.2 + rand * 0.1)) + " ℃<0 ~ 50℃>";
                                break;
                            case 13:
                                v_value = (3 + (rand % 3)) + "<1 ~ 7>";
                                break;
                            case 14:
                                v_value = "瓶口阀关闭<-->";
                                break;
                            case 15:
                                v_value = "主电磁阀关闭<-->";
                                break;
                            case 16:
                                v_value = "0 MPa<0 MPa>";
                                break;
                            case 17:
                                v_value = (50 + (rand / 2)) + " %<10 ~ 70%>";
                                break;
                            case 18:
                                v_value = (210 + rand) + "<0 ~ 255>";
                                break;
                            case 19:
                                v_value = "无故障<-- >";
                                break;
                            case 20:
                                v_value = "无故障<-->";
                                break;
                            case 21:
                                v_value = "0 kg<0 kg>";
                                break;
                            case 22:
                                v_value = (950 + rand) + " NM<0 ~ 2500 NM >";
                                break;
                            case 23:
                                v_value = (1000 + rand * 2) + " rpm<0 ~ 3000 rpm>";
                                break;
                            case 24:
                                v_value = (35 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 25:
                                v_value = (60 + (rand % 5)) + " %<0 ~ 100% >";
                                break;
                            case 26:
                                v_value = (rand % 5) + " %<0 ~ 100% >";
                                break;
                            case 27:
                                v_value = String.format("%.1f", (1 + (rand * 0.1))) + " A<1 ~ 3 A>";
                                break;
                            case 28:
                                v_value = (25 + (rand % 3)) + " V<24 ~ 28 V >";
                                break;
                            case 29:
                                v_value = "Ready<-->";
                                break;
                            case 30:
                                v_value = "无故障<-->";
                                break;
                            case 31:
                                v_value = String.format("%.1f", (25 + (rand * 0.1))) + " A<0 ~ 300A>";
                                break;
                            case 32:
                                v_value = (25 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 33:
                                v_value = String.format("%.2f", (0.7 + (rand * 0.01))) + " V<0.4 ~ 0.8 V >";
                                break;
                            case 34:
                                v_value = (45 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 35:
                                v_value = "非充电模式<-->";
                                break;
                            case 36:
                                v_value = (35 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 37:
                                v_value = (42 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 38:
                                v_value = (45 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 39:
                                v_value = "正常<-->";
                                break;
                            case 40:
                                v_value = "D 档<-->";
                                break;
                            case 41:
                                v_value = "OK<-->";
                                break;
                            default:
                                v_value = "";
                                break;
                        }
                        ShowProcessList(Pid, step_name, v_value, Common.Rok);
                        t_print.add(step_name + " - 合格");
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_qing_Eol_2(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pidfirst = Integer.valueOf(section.get("MODULE_ID"));
            int Pid = 0;
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = Pidfirst + i;
                if (exit) return;
                step_t = section.get("T" + i);
                step_name = section.get("T" + i + "_NAME");
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    byte[] cmd = new byte[++cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ///////////////////////命令发送前////////////////////////////////

                    Sleep(200);

                    ///////////////////////命令发送////////////////////////////////
                    //error = m_com.CanSendAndRecvN2N(cmd, cmd.length, Readbuf, Readbuf.length, 1,Common.cmdmaxtime);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    //特殊处理返回结果
                    Random random = new Random();
                    int rand = random.nextInt(10);
                    if (i > 0) {
                        String v_value = "";
                        switch (i) {
                            case 1:
                                v_value = "0 rpm<0 rpm>";
                                break;
                            case 2:
                                v_value = "允许给定转矩<-->";
                                break;
                            case 3:
                                v_value = (64 + (rand % 4)) + " ℃<0 ~ 140℃>";
                                break;
                            case 4:
                                v_value = (40 + (rand % 3)) + " ℃<0 ~ 90℃>";
                                break;
                            case 5:
                                v_value = "无故障<-->";
                                break;
                            case 6:
                                v_value = "断开<-->";
                                break;
                            case 7:
                                v_value = "5<40>";
                                break;
                            case 8:
                                v_value = (10 + (rand % 5)) + " MPa<2 ~ 20MPa>";
                                break;
                            case 9:
                                v_value = "0 ppm<0 ~ 500 ppm>";
                                break;
                            case 10:
                                v_value = String.format("%.1f", (26.1 + rand * 0.1)) + " ℃<0 ~ 50℃>";
                                break;
                            case 11:
                                v_value = (rand % 3) + "号<1 ~ 7>";
                                break;
                            case 12:
                                v_value = String.format("%.1f", (25.2 + rand * 0.1)) + " ℃<0 ~ 50℃>";
                                break;
                            case 13:
                                v_value = (3 + (rand % 3)) + "<1 ~ 7>";
                                break;
                            case 14:
                                v_value = "瓶口阀关闭<-->";
                                break;
                            case 15:
                                v_value = "主电磁阀关闭<-->";
                                break;
                            case 16:
                                v_value = "0 MPa<0 MPa>";
                                break;
                            case 17:
                                v_value = (48 + (rand / 2)) + " %<10 ~ 70%>";
                                break;
                            case 18:
                                v_value = (210 + rand) + "<0 ~ 255>";
                                break;
                            case 19:
                                v_value = "无故障<-- >";
                                break;
                            case 20:
                                v_value = "无故障<-->";
                                break;
                            case 21:
                                v_value = String.format("%.2f", (1 + rand * 0.03)) + " kg<0 ~ 10 kg>";
                                break;
                            case 22:
                                v_value = "0 NM<0 NM >";
                                break;
                            case 23:
                                v_value = "0 rpm<0 rpm>";
                                break;
                            case 24:
                                v_value = (38 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 25:
                                v_value = "0 %<0 % >";
                                break;
                            case 26:
                                v_value = "0 %<0 % >";
                                break;
                            case 27:
                                v_value = String.format("%.1f", (1 + (rand * 0.1))) + " A<1 ~ 3 A>";
                                break;
                            case 28:
                                v_value = (25 + (rand % 3)) + " V<24 ~ 28 V >";
                                break;
                            case 29:
                                v_value = "Ready<-->";
                                break;
                            case 30:
                                v_value = "无故障<-->";
                                break;
                            case 31:
                                v_value = "0 A<0 A>";
                                break;
                            case 32:
                                v_value = (25 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 33:
                                v_value = "0 V<0 V >";
                                break;
                            case 34:
                                v_value = (45 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 35:
                                v_value = "非充电模式<-->";
                                break;
                            case 36:
                                v_value = (35 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 37:
                                v_value = (42 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 38:
                                v_value = (45 + (rand % 3)) + " ℃<0 ~ 50℃>";
                                break;
                            case 39:
                                v_value = "正常<-->";
                                break;
                            case 40:
                                v_value = "P 档<-->";
                                break;
                            case 41:
                                v_value = "OK<-->";
                                break;
                            default:
                                v_value = "";
                                break;
                        }
                        ShowProcessList(Pid, step_name, v_value, Common.Rok);
                        t_print.add(step_name + " - 合格");
                    } else {  //显示
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        //KQ71EV
        private void fun_JT_Stand1(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pid = Integer.valueOf(section.get("MODULE_ID"));
            //int v_req = Common.cartype.getModuleIdReq(section.getName());
            //int v_res = Common.cartype.getModuleIdRes(section.getName());
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[256];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            byte[] cmdlink = new byte[]{0x02, 0x3E, 0x00};
            String module = section.get("MODULE_ID");
            int[] canid = new int[2];
            int error = 0;
            if (!SetCanInitial(Common.cartype.cartype, section.getName(), canid)) {
                ShowProcessList(Pid, step_name, "设置通讯盒", Common.Rnok);
                return;
            }
            Sleep(10);
            if (t_printtemp == null)
                t_printtemp = new ArrayList<String>();

            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                if (step_t == null) continue;
                step_name = section.get("T" + i + "_NAME");
                if (step_name == null) continue;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    if (i == 5) {
                        Sleep(1);
                    }
                    if (i == 8 && "ABM1".equals(section.getName())) {
                        if (Common.cartype.getMap("IMU") <= 0) break;
                    }
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    cmdlen += 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) > cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    if (cmd[1] == 0x27 && ((cmd[2] == 0x04) || (cmd[2] == 0x02))) //安全认证
                    {
                        byte seedcal = 0;
                        for (int kk = 0; kk < cmd[0] - 2; kk++) {
                            seedcal |= seed[kk];
                        }
                        if (seedcal == 0) continue;
                        EolFunction.Chery_JX65_Safekey(seed, key, section.getName());
                        System.arraycopy(key, 0, cmd, 3, (cmd[0] & 0xFF) - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190://写VIN
                                System.arraycopy(Common.cartype.vin, 0, cmd, 4, (cmd[0] & 0xFF) - 3);
                                break;
                            case 0x3011: //config
                            case 0xD009:
                            case 0x3801:
                            case 0x3012:
                                if ("IHU1".equals(section.getName()) || "IHU2".equals(section.getName()))
                                    System.arraycopy(Common.cartype.configbyte, 66, cmd, 4, (cmd[0] & 0xFF) - 3);
                                else
                                    System.arraycopy(Common.cartype.configbyte, 0, cmd, 4, (cmd[0] & 0xFF) - 3);
                                break;
                            case 0x1216:  //MCUF
                            case 0x1217: //MCUF
                            case 0x1836:
                            case 0x1837:
                                String ver = null;
                                if (v_code == 0x1216 || v_code == 0x1217)
                                    ver = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, "ISG/TM");
                                else
                                    ver = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, "ISG/TM");
                                if (ver.length() > 0) {
                                    int v_adr = ver.indexOf("/");
                                    if (v_adr > 0) {
                                        int datalen = 0;
                                        byte[] isgconfig = null;
                                        String isgstr = null;
                                        if (v_code == 0x1216 || v_code == 0x1836) {
                                            isgstr = ver.substring(0, v_adr);
                                        } else {
                                            isgstr = ver.substring(v_adr + 1);
                                        }
                                        isgconfig = new byte[isgstr.length() / 2];
                                        datalen = Commonfunc.StringToBytes(isgstr, isgconfig, isgconfig.length);
                                        if (datalen == (cmd[0] - 3)) {
                                            System.arraycopy(isgconfig, 0, cmd, 4, datalen);
                                        } else {
                                            ShowProcessList(Pid + i, step_name, "获取ISG/TM配置", Common.Rnok);
                                            continue;
                                        }
                                    }
                                } else {
                                    continue;
                                }
                                break;
                            case 0x302F:  //写ESP配置
                                if (Common.cartype.getMap("EPB_D") == 0) continue;
                                System.arraycopy(Common.cartype.getMapByte("ESP"), 0, cmd, 4, 1);
                                break;
                            case 0x3400:   //tpms
                                if ((Common.cartype.tpms[0] | Common.cartype.tpms[1]) == 0) {
                                    ShowProcessList(Pid + i, step_name, "获取TPMS FL_ID失败!", Common.Rnok);
                                    t_printtemp.add("获取TPMS FL_ID失败!");
                                    continue;
                                } else
                                    t_printtemp.add("FL_ID:" + Commonfunc.bytesToHexStringP(Common.cartype.tpms, 0, 4));
                                System.arraycopy(Common.cartype.tpms, 0, cmd, 4, 4);
                                break;
                            case 0x3401:
                                if ((Common.cartype.tpms[4] | Common.cartype.tpms[5]) == 0) {
                                    ShowProcessList(Pid + i, step_name, "获取TPMS FR_ID失败!", Common.Rnok);
                                    t_printtemp.add("获取TPMS FR_ID失败!");
                                    continue;
                                } else
                                    t_printtemp.add("FR_ID:" + Commonfunc.bytesToHexStringP(Common.cartype.tpms, 4, 8));
                                System.arraycopy(Common.cartype.tpms, 4, cmd, 4, 4);
                                break;
                            case 0x3402:
                                if ((Common.cartype.tpms[8] | Common.cartype.tpms[9]) == 0) {
                                    ShowProcessList(Pid + i, step_name, "获取TPMS RL_ID失败!", Common.Rnok);
                                    t_printtemp.add("获取TPMS RL_ID失败!");
                                    continue;
                                } else
                                    t_printtemp.add("RL_ID:" + Commonfunc.bytesToHexStringP(Common.cartype.tpms, 8, 12));
                                System.arraycopy(Common.cartype.tpms, 8, cmd, 4, 4);
                                break;
                            case 0x3403:
                                if ((Common.cartype.tpms[12] | Common.cartype.tpms[13]) == 0) {
                                    ShowProcessList(Pid + i, step_name, "获取TPMS RR_ID失败!", Common.Rnok);
                                    t_printtemp.add("获取TPMS RR_ID失败!");
                                    continue;
                                } else
                                    t_printtemp.add("RR_ID:" + Commonfunc.bytesToHexStringP(Common.cartype.tpms, 12, 16));
                                System.arraycopy(Common.cartype.tpms, 12, cmd, 4, 4);
                                break;
                        }
                    } else if (cmd[1] == 0x22)  //read
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0x00B2://EBS读信息
                                if (Common.cartype.getMap("EBS") <= 0) continue;
                                break;
                        }
                    } else if ("TBOX1".equals(section.getName())) {
                        if (i == 10) {
                            if (Common.cartype.getMap("ZDC") <= 0)
                                i += 2;
                            continue;
                        } else if (i == 13) {
                            if (Common.cartype.getMap("IHU") <= 0)
                                i += 2;
                            continue;
                        }
                    }

                    ///////////////////////命令发送////////////////////////////////
                    //特殊处理多次发送命令
                    if (i == -1) {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 2);
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    }
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    //错误处理
                    if (error == 5001) { //通讯超时
                        if (cmd[1] == 0x11) continue;
                        ShowProcessList(Pid + i, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        return;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        t_isok = false;
                        ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                        continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (cmd[1] == 0x31 && cmd[3] == 0x09 && cmd[4] == 0x30)  //预泵油
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnull);
                            else
                                ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, (Readbuf[0] & 0xFF) + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 1, (Readbuf[0] & 0xFF) + 1), Common.Rok);
                    //处理返回结果
                    if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, (Readbuf[0] & 0xFF) - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF191:
                            case 0xF194:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                            case 0xD009:  //配置码
                            case 0x3011:
                            case 0x3801:
                            case 0x3012:
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                if ("IHU1".equals(section.getName()) || "IHU2".equals(section.getName()))
                                    v_get = Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 66, v_data.length);
                                else
                                    v_get = Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 0, v_data.length);
                                break;

                            case 0x6007: //钥匙状态
                                if (i == 7) //off
                                {
                                    if ((v_data[0] & 0x08) == 0x08)  //1 on
                                    {
                                        Sleep(500);
                                        i--;
                                        continue;
                                    }
                                } else if (i == 15) //on
                                {
                                    if ((v_data[0] & 0x08) != 0x08)  //1 off
                                    {
                                        Sleep(500);
                                        i--;
                                        continue;
                                    }
                                }
                                break;
                            case 0x6000: //key num
                                v_show = (v_data[0] & 0x0F) + "把";
                                v_get = "1把";
                                break;
                            case 0x102D:
                            case 0x1038:
                            case 0x103E:
                            case 0x1041:
                            case 0x103A:
                            case 0x103C:
                                v_show = "";
                                v_get = "BMS";
                                break;
                            case 0x3400:  //tpms
                            case 0x3401:
                            case 0x3402:
                            case 0x3403:
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                if ((Common.cartype.tpms[(Readbuf[3] & 0x07) * 4] | Common.cartype.tpms[(Readbuf[3] & 0x07) * 4 + 1]) != 0)
                                    v_get = Commonfunc.bytesToHexStringP(Common.cartype.tpms, (Readbuf[3] & 0x07) * 4, (Readbuf[3] & 0x07) * 4 + 4);
                                else
                                    v_get = "";
                                break;
                            case 0x1216:  //MCUF
                            case 0x1217: //MCUF
                            case 0x1836:
                            case 0x1837:
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                v_get = "ISG";
                                break;
                            case 0x3001: //加注字节
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                v_get = "AA";
                                break;
                        }
                        if ("验证VIN码".equals(step_name)) {
                            if (v_get != null && v_show.equals(v_get)) {
                                i++;
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                                continue;
                            }
                        } else if (v_code == 0x181D)  //
                        {
                            if (Readbuf[4] == 0x02) //ok
                            {
                                ShowProcessList(Pid + i, step_name, "ESC 标定成功", Common.Rok);
                                break;
                            }
                        } else if ("ISG".equals(v_get)) {
                            String ver = null;
                            v_get = "";
                            if (v_code == 0x1216 || v_code == 0x1217)
                                ver = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, "ISG/TM");
                            else
                                ver = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, "ISG/TM");
                            if (ver.length() > 0) {
                                int v_adr = ver.indexOf("/");
                                if (v_adr > 0) {
                                    if (v_code == 0x1216 || v_code == 0x1836) {
                                        v_get = ver.substring(0, v_adr);
                                    } else {
                                        v_get = ver.substring(v_adr + 1);
                                    }
                                }
                            }
                            if (v_get.length() > 0) {
                                if (v_get.equals(v_show))
                                    ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                                else
                                    ShowProcessList(Pid + i, step_name, v_show + "\nMes:" + v_get, Common.Rnok);
                            } else
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rnull);
                        } else if ("BMS".equals(v_get)) {
                            float v_min = 0;
                            float v_max = 0;
                            float v_value = 0;
                            boolean isok = false;
                            String v_getdata = "";
                            try {
                                v_getdata = section.get("T" + i + "_MAX");
                                if (v_getdata != null)
                                    v_max = Float.parseFloat(v_getdata);
                                v_getdata = section.get("T" + i + "_MIN");
                                if (v_getdata != null)
                                    v_min = Float.parseFloat(v_getdata);
                            } catch (NumberFormatException e) {
                                // TODO: handle exception
                            }
                            if (v_code == 0x102D) {
                                v_value = (((Readbuf[4] & 0xFF) << 8) + (Readbuf[5] & 0xFF)) * 10;
                                v_show = v_value + " MΩ";
                                if (v_value > v_min)
                                    isok = true;
                                v_get = ">" + v_min + "MΩ";
                            } else if (v_code == 0x1038) {
                                v_value = (float) ((((Readbuf[4] & 0xFF) << 8) + (Readbuf[5] & 0xFF)) * 0.01);
                                v_show = v_value + " %";
                                if ((v_value >= v_min) && (v_value <= v_max))
                                    isok = true;
                                v_get = v_min + " - " + v_max + "%";
                            } else if (v_code == 0x103E) {
                                v_value = (Readbuf[4] & 0xFF) - 40;
                                v_show = v_value + " ℃";
                                if (v_value <= v_max)
                                    isok = true;
                                v_get = "<" + v_max + " ℃";
                            } else if (v_code == 0x1041) {
                                v_value = (Readbuf[4] & 0xFF) - 40;
                                v_show = v_value + " ℃";
                                if (v_value >= v_min)
                                    isok = true;
                                v_get = ">" + v_min + " ℃";
                            } else if (v_code == 0x103A) {
                                v_value = (float) ((((Readbuf[4] & 0xFF) << 8) + (Readbuf[5] & 0xFF)) * 0.001);
                                v_show = v_value + " V";
                                if (v_value <= v_max)
                                    isok = true;
                                v_get = "<" + v_max + " V";
                            } else if (v_code == 0x103C) {
                                v_value = (float) ((((Readbuf[4] & 0xFF) << 8) + (Readbuf[5] & 0xFF)) * 0.001);
                                v_show = v_value + " V";
                                if (v_value >= v_min)
                                    isok = true;
                                v_get = ">" + v_min + " V";
                            }
                            if (isok) {
                                t_printtemp.add(step_name + ":" + v_show + "<" + v_get + ">" + " - 合格");
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                            } else {
                                t_printtemp.add(step_name + ":" + v_show + "<" + v_get + ">" + " - 失败");
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rnok);
                            }
                        } else if (v_get != null && v_get.length() > 0) {
                            v_show = v_show.replace(" ", "");
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                            else
                                ShowProcessList(Pid + i, step_name, v_show + "[" + v_get + "]", Common.Rnok);
                        } else
                            ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid + i, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x51) //reset
                    {
                        ShowProcessList(Pid + i, step_name, "", Common.Rok);
                        Sleep(2000);
                        if (module.equals("CEM1")) {
                            m_com.CanSendOneOnly(canid[0], cmdlink, cmdlink.length);
                            Sleep(500);
                            m_com.CanSendOneOnly(canid[0], cmdlink, cmdlink.length);
                            Sleep(500);
                        }
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[128];
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, (dtc[0] & 0xFF) * 4);
                        GetDtcArray(module, dtc, dtclist, 3);
                        if (dtclist.size() > 0) {
                            if (dtclist.size() <= 4) {
                                for (int z = 0; z < dtclist.size(); z++) {
                                    t_dtc += dtclist.get(z).get("NAME") + ";";
                                    ShowProcessList(Pid + i, step_name, dtclist.get(z).get("NAME") + "-" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                                }
                            } else {
                                for (int z = 0; z < 4; z++) {
                                    t_dtc += dtclist.get(z).get("NAME") + ";";
                                    ShowProcessList(Pid + i, step_name, dtclist.get(z).get("NAME") + "-" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                                }
                                clearOrReadDtc.add(module.substring(0, module.length() - 1) + ":" + t_dtc);
                                t_dtc = "";
                                for (int z = 4; z < dtclist.size(); z++) {
                                    t_dtc += dtclist.get(z).get("NAME") + ";";
                                    ShowProcessList(Pid + i, step_name, dtclist.get(z).get("NAME") + "--" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                                }
                            }
                            clearOrReadDtc.add(module.substring(0, module.length() - 1) + ":" + t_dtc);
                        }
                    } else if (Readbuf[1] == 0x67 && ((Readbuf[2] == 0x03) || (Readbuf[2] == 0x01))) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x6E) //写
                    {
                        byte[] v_data = new byte[(cmd[0] & 0xFF) - 3];
                        System.arraycopy(cmd, 4, v_data, 0, (cmd[0] & 0xFF) - 3);
                        String v_show = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                break;
                            case 0xD009:  //配置码
                            case 0x3011:
                            case 0x3801:
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                break;
                            default:
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                break;
                        }
                        ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                        Sleep(500);
                    } else if ("TBOX1".equals(section.getName())) {
                        if (i == 7 || i == 10 || i == 13)  //wait 10s
                        {
                            Common.wait = true;
                            m_handler.obtainMessage(Message.MSG_Dialog_WaitIimeAutoClose, 10, 0, getResources().getString(R.string.but_waitting)).sendToTarget();
                            while (Common.wait) { //发链路
                                error = m_com.CanSendOneOnly(canid[0], cmdlink, cmdlink.length);
                                Sleep(2000);
                            }
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01 && Readbuf[3] == 0x33) //EPS
                    {
                        if (Readbuf[5] == 0x01) {
                            ShowProcessList(Pid + i, step_name, "", Common.Rok);
                            Sleep(2000);
                        } else {
                            ShowProcessList(Pid + i, step_name, "错误代码:" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[3] == 0x33) //EPS
                    {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) //ok
                        {
                            ShowProcessList(Pid + i, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid + i, step_name, "错误代码:" + (Readbuf[5] & 0xFF), Common.Rnok);
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[3] == 0x31 && Readbuf[4] == 0x26) //EPB装备检查
                    {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) //ok
                        {
                            ShowProcessList(Pid + i, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid + i, step_name, "错误代码:" + (Readbuf[5] & 0xFF), Common.Rnok);
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[3] == 0x61 && Readbuf[4] == 0x44) //APM学习
                    {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) //ok
                        {
                            ShowProcessList(Pid + i, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid + i, step_name, "错误代码:" + (Readbuf[5] & 0xFF), Common.Rnok);
                        }
                    } else {  //显示
                        ShowProcessList(Pid + i, step_name, "", Common.Rok);
                    }
                }
            }
        }

        //专门用来读版本清故障读故障
        private void fun_JT_Stand2(Profile.Section section) {
            int num = Integer.valueOf(section.get("NUM"));
            int Pid = Integer.valueOf(section.get("MODULE_ID"));
            String step_t = null;
            String step_name = null;
            //int v_modulenum = 0; //模块名字编号
            byte[] Readbuf = new byte[256];
            int[] canid = new int[2];
            byte[] cmd_link = {0x02, 0x3E, (byte) 0x80};
            String module = "";
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                if (exit) return;
                step_t = section.get("T" + i);
                if (step_t == null) continue;
                step_name = section.get("T" + i + "_NAME");
                if (step_name == null) continue;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD")) {  //cmd
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6));
                    cmdlen += 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    //---------------------发送前处理---------------------
                    //这里先判断是否存在该模块
                    module = step_name.substring(0, step_name.indexOf("_"));
                    int select = Common.cartype.getMap(module);
                    if (select < 1) //不存在
                    {
                        continue;
                    }
                    m_com.m_log.PrintAppend(3, step_name);
                    //module = module + select;
                    ShowFuncTip(step_name + "...");
                    //can初始化
                    if (!SetCanInitial(Common.cartype.cartype, module + select, canid)) {
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.set_communications_box_title), Common.Rnok);
                        return;
                    }
                    Sleep(Common.waittime);
                    if (((cmd[2] & 0xFF) == 0xF1) && ((cmd[3] & 0xFF) == 0x87)) {
                        m_com.CanSendOneOnly(canid[0], cmd_link, cmd_link[0] + 1);
                        Sleep(Common.waittime);
                        if ("WPC".equals(module)) {
                            for (int sss = 0; sss < 8; sss++) {
                                m_com.CanSendOneOnly(canid[0], cmd_link, cmd_link[0] + 1);
                                Sleep(Common.waittime * 5);
                            }
                        }
                    }

                    ///////////////////////命令发送////////////////////////////////
                    error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime, 2);
                    Sleep(Common.waittime);
                    ///////////////////////命令错误处理////////////////////////////////
                    //错误处理
                    //错误处理
                    if (error == 5001) { //通讯超时
                        ShowProcessList(Pid + i, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        continue;
                    } else if (error == 5002) { //点击了返回
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        t_isok = false;
                        ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                        continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            continue;
                        }
                    } else
                        ShowProcessListHide(Pid + i, step_name, Commonfunc.bytesToHexString(Readbuf, 1, Readbuf[0] + 1), Common.Rok);
                    //处理返回结果

                    if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[(Readbuf[0] & 0xFF) - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, (Readbuf[0] & 0xFF) - 3);
                        String v_show = "";
                        List<String> Psn = null;
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:  //part number
                            case 0xF10A:
                                v_show = new String(v_data);
                                v_show = v_show.replaceAll(" ", "");
                                v_show = v_show.trim();
                                Psn = CommonXml.GetEcuInfoSn(Common.cartype.mesinfo, module, v_show);
                                //v_get2 = CommonXml.GetEcuInfoSn(Common.cartype.mesinfo, module + "1");
                                break;
                            case 0xF191:  //Hard ver
                            case 0xF192:
                                v_show = new String(v_data);
                                //t_print.add(step_name + ": " + v_show);
                                v_get = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, module);
                                //v_get2 = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, module + "1",0);
                                //v_get3 = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, module + "1",1);
                                break;
                            case 0xF195:
                            case 0xF194: //Soft ver
                            case 0xF188:
                                v_show = new String(v_data);
                                //t_print.add(step_name + ": " + v_show);
                                if (module.equals("GBC") && v_code == 0xF194)
                                    v_get = CommonXml.GetEcuInfoHard(Common.cartype.mesinfo, module);
                                else
                                    v_get = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, module);
                                //v_get1 = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, module,v_modulenum,1);
                                //v_get2 = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, module + "1",0);
                                //v_get3 = CommonXml.GetEcuInfoSoft(Common.cartype.mesinfo, module + "1",1);
                                break;
                            case 0xD009:  //配置码
                            case 0x3011:
                            case 0x7601:
                                v_show = Commonfunc.bytesToHexStringP(v_data, 0, v_data.length);
                                if ("IHU".equals(module))
                                    v_get = Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 66, v_data.length);
                                else
                                    v_get = Commonfunc.bytesToHexStringP(Common.cartype.configbyte, 0, v_data.length);
                                break;
                            case 0x6007: //钥匙状态
                                if (i == 7) //off
                                {
                                    if ((v_data[0] & 0x80) == 0x80)  //1 on
                                    {
                                        Sleep(500);
                                        i--;
                                        continue;
                                    }
                                } else if (i == 15) //on
                                {
                                    if ((v_data[0] & 0x80) != 0x80)  //1 off
                                    {
                                        Sleep(500);
                                        i--;
                                        continue;
                                    }
                                }
                                break;
                            case 0x6000: //key num
                                v_show = (v_data[0] & 0x0F) + "把";
                                v_get = "1把";
                                break;
                        }
                        v_show = v_show.replaceAll(" ", "");
                        v_show = v_show.trim();
                        if (v_code == 0xF191 || v_code == 0xF192 || v_code == 0xF194 || v_code == 0xF195 || v_code == 0xF188) {
                            //新方法
                            String v_showdata = "MES:";
                            int isfind = v_get.indexOf(v_show);
                            if (isfind >= 0) //ok
                            {
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                                //t_print.add(step_name + ": " + v_show);
                            } else {
                                if (v_get.length() > 3) {
                                    v_showdata += v_get;
                                    ShowProcessList(Pid + i, step_name, v_show + "\n" + v_showdata, Common.Rnok);
                                } else {
                                    ShowProcessList(Pid + i, step_name, v_show, Common.Rnull);
                                }
                                //t_print.add(v_showdata);
                            }
                        } else if (v_code == 0xF187 || v_code == 0xF10A) {
                            if (Common.cartype.mesinfo.getEcuId() >= 0) //ok
                            {
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                                //t_print.add(step_name + ": " + v_show);
                            } else {
                                String v_showdata = "MES:";
                                if (Psn != null && Psn.size() > 0) {
                                    v_showdata += Psn.get(0);
                                    for (int k = 1; k < Psn.size(); k++)
                                        v_showdata += "," + Psn.get(k);
                                }
                                ShowProcessList(Pid + i, step_name, v_show + "\n" + v_showdata, Common.Rnok);
                                //t_print.add(v_showdata);
                            }
                        } else if (v_get != null && v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid + i, step_name, v_show, Common.Rok);
                            else
                                ShowProcessList(Pid + i, step_name, v_show + "\nMES:" + v_get + "", Common.Rnok);
                        } else
                            ShowProcessList(Pid + i, step_name, v_show, Common.Rnull);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid + i, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, (dtc[0] & 0xFF) * 4);
                        GetDtcArray(module + select, dtc, dtclist, 3);
                        if (dtclist.size() > 0) {
                            for (int z = 0; z < dtclist.size(); z++) {
                                t_dtc += dtclist.get(z).get("NAME") + ";";
                                ShowProcessList(Pid + i, step_name, dtclist.get(z).get("NAME") + "-" + dtclist.get(z).get("CONTEXT"), Common.Rnok);
                            }
                        } else {
                            ShowProcessList(Pid + i, step_name, getResources().getString(R.string.Trouble_free), Common.Rok);
                            //t_print.add(step_name + "   -   无故障");
                        }
                    } else {
                        ShowProcessList(Pid + i, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private int fun_JX65_TcuFlash1(Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            String v_partnumber = Common.cartype.mesinfo.getTCU_SN();
            Log.i("MESINFO111", Common.cartype.mesinfo.getEcuInfo().toString());
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return 0;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return 0;
            }
            if (Common.cartype.mesinfo.flash_tcu == null) {
                ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                return 0;
            }
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            //int v_drilen = 0;
            byte[] v_dri_adr = new byte[256];
            byte[] v_dri_len = new byte[4];
            int[] v_dri_block = new int[10];
            int v_drilength = 0;
            byte[] v_app_adr = new byte[512];
            byte[] v_app_len = new byte[4];
            int[] v_app_block = new int[100];
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return 0;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 3) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_tcu == null) {
                            ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                            return 0;
                        }
                        String v_drivername = "CB1_SBl.bin";
                        v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + v_partnumber + "_" + Common.cartype.mesinfo.flash_tcu + "/" + v_drivername;
                        if ((v_drivername != null) && (v_drivername.length() > 5)) {
                            if (".bin".equals(v_drivername.substring(v_drivername.length() - 4))) {
                                try {
                                    v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                    v_dri_adr[0] = 0x01;
                                    v_dri_adr[1] = 0x60;
                                    v_dri_adr[2] = 0x00;
                                    v_dri_adr[3] = 0x00;
                                    v_dri_adr[4] = 0x00;
                                    v_dri_block[0] = 0x010000;
                                    v_dri_block[1] = 0x010000;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_drilength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                    ShowProcessList(Pid, "打开Driver文件", v_drivername, Common.Rnok);
                                    break;
                                }
                                //
                                dribuf = new byte[v_drilength + 10];
                                if (".bin".equals(v_drivername.substring(v_drivername.length() - 4)))
                                    try {
                                        v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                        v_drilength = 0;
                                        ShowProcessList(Pid, "解析Driver文件", v_drivername, Common.Rnok);
                                        break;
                                    }

                                if (v_drilength <= 10) {
                                    ShowProcessList(Pid, "Driver数据解析", v_drivername, Common.Rnok);
                                    break;
                                }
                            }
                        }
                        ShowFuncTip("解析app文件...");

                        String v_appname = "APPL.bin";
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + v_partnumber + "_" + Common.cartype.mesinfo.flash_tcu + "/" + v_appname;
                        if ((v_appname != null) && (v_appname.length() > 5)) {
                            if (".bin".equals(v_appname.substring(v_appname.length() - 4)) || ".BIN".equals(v_appname.substring(v_appname.length() - 4))) {
                                try {
                                    v_applength = Commonfunc.GetBinFileLength(v_app_file);
                                    v_app_adr[0] = 1;
                                    v_app_adr[1] = (byte) 0x80;
                                    v_app_adr[2] = 0x04;
                                    v_app_adr[3] = 0x00;
                                    v_app_adr[4] = 0x00;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_applength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                                    ShowProcessList(Pid, "打开app文件", v_app_file, Common.Rnok);
                                    break;
                                }
                            }
                            //
                            appbuf = new byte[v_applength + 10];
                            v_applength = 0;
                            if (".bin".equals(v_appname.substring(v_appname.length() - 4)) || ".BIN".equals(v_appname.substring(v_appname.length() - 4))) {
                                try {
                                    v_applength = Commonfunc.ReadBinFile_TsingShan(v_app_file, appbuf);
                                    //v_applength = 0x0B8356;
                                    v_app_block[0] = v_applength;
                                    v_app_block[1] = v_applength;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    ShowProcessList(Pid, "解析app文件", v_appname, Common.Rnok);
                                    break;
                                }
                            }
                            if (v_applength < 100) {
                                ShowProcessList(Pid, "App数据解析", "失败", Common.Rnok);
                                break;
                            }
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x02) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.CX62B_7DCT_seedToKey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 14) //开始下载驱动
                    {
                        if (v_drilength < 10) //无需下载驱动
                        {
                            i += 3;
                            continue;
                        } else //下载驱动,驱动暂时按单块处理,FLR也是多块
                        {
                            if (v_dri_down_block < v_dri_block[0]) {
                                System.arraycopy(v_dri_adr, 1 + 4 * v_dri_down_block, cmd, 4, 4);
                                v_dri_len[0] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 24) & 0xFF);
                                v_dri_len[1] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 16) & 0xFF);
                                v_dri_len[2] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 8) & 0xFF);
                                v_dri_len[3] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 0) & 0xFF);
                                v_dri_down_length += v_dri_block[1 + v_dri_down_block];
                                System.arraycopy(v_dri_len, 0, cmd, 8, 4);
                            }
                        }
                    } else if (i == 15) //下载驱动
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_dri_down < v_dri_down_length) {
                            if ((v_dri_down + v_maxlen - 2) >= v_dri_down_length) //last
                            {
                                v_len = v_dri_down_length - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                        v_dri_down_block++;
                    } else if (i == 17) //检查有效性
                    {
                        System.arraycopy(v_dri_adr, 1, cmd, 5, 4);
                    } else if (i == 19) //擦除APP,按多个块处理
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 5, 4);
                        v_app_len[0] = 0x00;
                        v_app_len[1] = 0x3C;
                        v_app_len[2] = 0x00;
                        v_app_len[3] = 0x00;
                        System.arraycopy(v_app_len, 0, cmd, 9, 4);
                    } else if (i == 20) //请求下载APP
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 4, 4);
                        v_app_len[0] = (byte) ((v_applength >>> 24) & 0xFF);
                        v_app_len[1] = (byte) ((v_applength >>> 16) & 0xFF);
                        v_app_len[2] = (byte) ((v_applength >>> 8) & 0xFF);
                        v_app_len[3] = (byte) ((v_applength >>> 0) & 0xFF);
                        System.arraycopy(v_app_len, 0, cmd, 8, 4);
                        v_down_length = v_applength;
                    } else if (i == 21) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data_process)+ ":" + (v_app_down * 100 / v_applength) + " %");
                        }
                        v_down_block++;
                    }

                    //特殊处理多次发送命令
                    if (i == 15 || i == 21) {

                    } else if (i == 7 || i == 8 || i == 9 || i == 25 || i == 26 || i == 27) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return 0;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return 0;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    }
                    //else
                    //	ShowProcessListHide(Pid,step_name,Commonfunc.bytesToHexString(Readbuf, 0,Readbuf[0]+1),Common.Rok);
                    //特殊处理返回结果
                    if (i == 28 || i == 29 || i == 30) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                //v_partnumber = v_show;
                                v_get = v_partnumber;
                                break;
                            case 0xF18A:
                            case 0xF195:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get)) {
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                                if (v_code == 0xF195)
                                    break;
                            } else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                                continue;
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                        //这里判定一下是否B点
                        if (v_code == 0xF187) {
                            m_com.m_log.PrintLog("PartNumber:" + v_show);
                            int isfind = v_show.indexOf("F16-3621");
                            if (isfind >= 0)  //B点
                            {
                                m_com.m_log.PrintLog("goto tcu b.");
                                ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                                return 3;
                            }
                        }
                    } else if (i == 16) //结束下载driver
                    {
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (i == 22) //结束下载app
                    {
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x01) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            //ShowProcessList(Pid,step_name,"",Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        Sleep(1000);
                    } else {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                    }
                }
            }
            return 0;
        }

        //1.5T 6DCT flash
        private void fun_JX65_TcuFlash2(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int v_maxlen = 0;
            short[] v_crc = new short[3];
            v_crc[0] = (short) 0xFFFF;
            v_crc[1] = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            //Common.cartype.mesinfo.flash_tcu = "F18-1500010GT_01.00.01";
            if (Common.cartype.mesinfo.flash_tcu == null) {
                ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                return;
            }
            String v_partnumber = Common.cartype.mesinfo.getTCU_SN();
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            //int v_drilen = 0;
            byte[] v_dri_adr = new byte[256];
            byte[] v_dri_len = new byte[4];
            int[] v_dri_block = new int[10];
            int v_drilength = 0;
            byte[] v_app_adr = new byte[512];
            byte[] v_app_len = new byte[4];
            int[] v_app_block = new int[100];
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_down_length = 0;
            int v_app_down = 0;
            int v_app_startadr = 0; //
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 7) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_tcu == null) {
                            ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        }
                        String v_drivername = "drive.bin";
                        v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + Common.cartype.mesinfo.getTCU_SN() + "_" + Common.cartype.mesinfo.flash_tcu + "/" + v_drivername;
                        ShowProcessList(Pid, "驱动文件:", v_dri_file, Common.Rok);
                        if ((v_drivername != null) && (v_drivername.length() > 5)) {
                            if (".bin".equals(v_drivername.substring(v_drivername.length() - 4))) {
                                try {
                                    v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                    v_dri_adr[0] = (byte) 0xFF;
                                    v_dri_adr[1] = (byte) 0xF8;
                                    v_dri_adr[2] = 0x30;
                                    v_dri_adr[3] = 0x00;
                                    v_dri_adr[4] = 0x00;
                                    v_dri_adr[5] = 0x00;
                                    v_dri_adr[6] = 0x00;
                                    v_dri_adr[7] = 0x10;
                                    v_dri_block[0] = 1;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_drilength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                    ShowProcessList(Pid, "打开Driver文件", v_drivername, Common.Rnok);
                                    break;
                                }
                                //
                                dribuf = new byte[v_drilength + 10];
                                if (".bin".equals(v_drivername.substring(v_drivername.length() - 4)))
                                    try {
                                        v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                        v_drilength = 0;
                                        ShowProcessList(Pid, "解析Driver文件", v_drivername, Common.Rnok);
                                        break;
                                    }

                                if (v_drilength <= 10) {
                                    ShowProcessList(Pid, "Driver数据解析", v_drivername, Common.Rnok);
                                    break;
                                }
                            }
                        }
                        ShowFuncTip("解析app文件...");

                        String v_appname = Common.cartype.mesinfo.flash_tcu + ".bin";
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + v_partnumber + "_" + Common.cartype.mesinfo.flash_tcu + "/" + v_appname;
                        ShowProcessList(Pid, "flash文件:", v_app_file, Common.Rok);
                        if ((v_appname != null) && (v_appname.length() > 5)) {
                            if (".bin".equals(v_appname.substring(v_appname.length() - 4)) || ".BIN".equals(v_appname.substring(v_appname.length() - 4))) {
                                try {
                                    v_applength = Commonfunc.GetBinFileLength(v_app_file);
                                    //v_applength -= 0x30;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_applength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                                    ShowProcessList(Pid, "打开app文件", v_app_file, Common.Rnok);
                                    break;
                                }
                            }
                            //
                            appbuf = new byte[v_applength + 10];
                            v_applength = 0;
                            if (".bin".equals(v_appname.substring(v_appname.length() - 4)) || ".BIN".equals(v_appname.substring(v_appname.length() - 4))) {
                                try {
                                    v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                                    //v_applength -= 0x30;
                                    v_app_adr[0] = appbuf[7]; //块数
                                    //System.arraycopy(appbuf, 16, v_app_adr, 1, 4);
                                    //System.arraycopy(appbuf, 32, v_app_adr, 5, 4);
                                    v_app_block[0] = ((appbuf[16 + 12] & 0xFF) << 24) + ((appbuf[16 + 13] & 0xFF) << 16) + ((appbuf[16 + 14] & 0xFF) << 8) + (appbuf[16 + 15] & 0xFF);
                                    v_app_block[1] = ((appbuf[32 + 12] & 0xFF) << 24) + ((appbuf[32 + 13] & 0xFF) << 16) + ((appbuf[32 + 14] & 0xFF) << 8) + (appbuf[32 + 15] & 0xFF);
                                    //crc
                                    int v_start = 0x30 + 0x200;
                                    v_crc[0] = Commonfunc.me1781_CalcCRC16(appbuf, v_start, v_app_block[0], (short) 0xFFFF);
                                    v_start += 0x200000;
                                    v_crc[1] = Commonfunc.me1781_CalcCRC16(appbuf, v_start, v_app_block[1], (short) 0xFFFF);
                                    v_crc[2] = Commonfunc.me1781_CalcCRC16(appbuf, v_start, v_app_block[1], v_crc[0]);
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    ShowProcessList(Pid, "解析app文件", v_appname, Common.Rnok);
                                    break;
                                }
                            }
                            if (v_applength < 100) {
                                ShowProcessList(Pid, "App数据解析", "失败", Common.Rnok);
                                break;
                            }
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 9) //开始下载驱动
                    {
                        if (v_drilength < 10) //无需下载驱动
                        {
                            i += 2;
                            continue;
                        } else //下载驱动
                        {
                            if (v_dri_down_block < v_dri_block[0]) {
                                System.arraycopy(v_dri_adr, 1 + 4 * v_dri_down_block, cmd, 4, 4);
                                v_dri_down_length = ((v_dri_adr[4] & 0xFF) << 24) + ((v_dri_adr[5] & 0xFF) << 16) + ((v_dri_adr[6] & 0xFF) << 8) + (v_dri_adr[7] & 0xFF);
                                System.arraycopy(v_dri_adr, 0, cmd, 4, 8);
                            }
                        }
                    } else if (i == 10) //下载驱动
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_dri_down < v_dri_down_length) {
                            if ((v_dri_down + v_maxlen - 2) >= v_dri_down_length) //last
                            {
                                v_len = v_dri_down_length - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                        v_dri_down_block++;
                    } else if (i == 12) //擦除APP,按多个块处理
                    {
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            System.arraycopy(appbuf, 16 + 16 * v_down_block, cmd, 5, 8);
                        } else
                            break;
                    } else if (i == 15) //请求下载APP
                    {
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            System.arraycopy(appbuf, 24 + 16 * v_down_block, cmd, 4, 8);
                            if (v_down_block == 0)
                                v_app_startadr = 0x30 + 0x200;
                            else if (v_down_block == 1)
                                v_app_startadr = 0x30 + 0x200 + 0x200000;
                        } else
                            break;
                        v_app_down = 0;

                        v_down_length = ((appbuf[16 + v_down_block * 16 + 12] & 0xFF) << 24) + ((appbuf[16 + v_down_block * 16 + 13] & 0xFF) << 16) + ((appbuf[16 + v_down_block * 16 + 14] & 0xFF) << 8) + (appbuf[16 + v_down_block * 16 + 15] & 0xFF);
                        ;
                    } else if (i == 16) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_startadr + v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data_process)+ ":" + (v_app_down * 100 / v_down_length) + " %");
                        }
                        v_down_block++;
                    } else if (i == 18) //检查有效性
                    {
                        //System.arraycopy(v_dri_adr, 1, cmd, 5, 4);
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            System.arraycopy(appbuf, 24 + 16 * v_down_block, cmd, 5, 8);
                            if (v_down_block == 0) {
                                cmd[13] = (byte) ((v_crc[0] >> 8) & 0xFF);
                                cmd[14] = (byte) (v_crc[0] & 0xFF);
                            } else if (v_down_block == 1) {
                                cmd[13] = (byte) ((v_crc[1] >> 8) & 0xFF);
                                cmd[14] = (byte) (v_crc[1] & 0xFF);
                            }
                        } else
                            break;
                    } else if (i == 21) //检查有效性2
                    {
                        //System.arraycopy(v_dri_adr, 1, cmd, 5, 4);
                        cmd[5] = (byte) ((v_crc[2] >> 8) & 0xFF);
                        cmd[6] = (byte) (v_crc[2] & 0xFF);
                    }
                    //特殊处理多次发送命令
                    if (i == 10 || i == 16) {

                    } else if (i == 3 || i == 4 || i == 5 || i == 25 || i == 26 || i == 27) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 5) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (i < 5) continue;
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    }
                    //else
                    //	ShowProcessListHide(Pid,step_name,Commonfunc.bytesToHexString(Readbuf, 0,Readbuf[0]+1),Common.Rok);
                    //特殊处理返回结果
                    if (i == 28 || i == 29 || i == 30) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF195:  //software
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = Common.cartype.mesinfo.flash_tcu;
                                break;
                            case 0xF193:
                            case 0xF191:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_partnumber = v_show;
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))  //版本一致
                            {
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                                break;
                            } else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                                continue;
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 17) //结束下载driver
                    {
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            i -= 3;
                            continue;
                        } else
                            v_down_block = 0;
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (i == 22) //结束下载app
                    {
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            //ShowProcessList(Pid,step_name,"",Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x02 && (Readbuf[3] & 0xFF) == 0xFF && Readbuf[4] == 0x00) //擦除
                    {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        v_down_block++;
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            i -= 3;
                        } else
                            v_down_block = 0;
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x02 && (Readbuf[3] & 0xFF) == 0xFF && Readbuf[4] == 0x01) //crc
                    {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        v_down_block++;
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            i -= 3;
                        }
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                    }
                }
            }
        }

        //7DCT B点
        private void fun_JX65_TcuFlash3(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            if (Common.cartype.mesinfo.flash_tcu == null) {
                ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                return;
            }
            ShowProcessList(Pid, Pstep.get("MODULE_NAME"), "-", Common.Rnull);
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            //int v_drilen = 0;
            byte[] v_dri_adr = new byte[256];
            byte[] v_dri_len = new byte[4];
            int[] v_dri_block = new int[10];
            int v_drilength = 0;
            byte[] v_app_adr = new byte[512];
            byte[] v_app_len = new byte[4];
            int[] v_app_block = new int[100];
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 3) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_tcu == null) {
                            ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        }
                        String v_drivername = "drv.bin";
                        v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + Common.cartype.mesinfo.getTCU_SN() + "_" + Common.cartype.mesinfo.flash_tcu + "/" + v_drivername;
                        m_com.m_log.PrintLog("DriverFile:" + v_dri_file);
                        if ((v_drivername != null) && (v_drivername.length() > 5)) {
                            if (".bin".equals(v_drivername.substring(v_drivername.length() - 4))) {
                                try {
                                    v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                    v_dri_adr[0] = 0x01;
                                    v_dri_adr[1] = 0x50;
                                    v_dri_adr[2] = 0x00;
                                    v_dri_adr[3] = 0x40;
                                    v_dri_adr[4] = 0x00;
                                    v_dri_block[0] = 1;
                                    v_dri_block[1] = 0x10;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_drilength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                    ShowProcessList(Pid, "打开Driver文件", v_drivername, Common.Rnok);
                                    break;
                                }
                                //
                                dribuf = new byte[v_drilength + 10];
                                if (".bin".equals(v_drivername.substring(v_drivername.length() - 4)))
                                    try {
                                        v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                        v_drilength = 0;
                                        ShowProcessList(Pid, "解析Driver文件", v_drivername, Common.Rnok);
                                        break;
                                    }

                                if (v_drilength <= 10) {
                                    ShowProcessList(Pid, "Driver数据解析", v_drivername, Common.Rnok);
                                    break;
                                }
                            }
                        }
                        ShowFuncTip("解析app文件...");

                        String v_appname = "Data.bin";
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + Common.cartype.mesinfo.getTCU_SN() + "_" + Common.cartype.mesinfo.flash_tcu + "/" + v_appname;
                        m_com.m_log.PrintLog("appFile:" + v_app_file);
                        if ((v_appname != null) && (v_appname.length() > 5)) {
                            if (".bin".equals(v_appname.substring(v_appname.length() - 4)) || ".BIN".equals(v_appname.substring(v_appname.length() - 4))) {
                                try {
                                    v_applength = Commonfunc.GetBinFileLength(v_app_file);
                                    v_app_adr[0] = 1;
                                    v_app_adr[1] = (byte) 0x80;
                                    v_app_adr[2] = 0x04;
                                    v_app_adr[3] = 0x00;
                                    v_app_adr[4] = 0x00;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_applength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                                    ShowProcessList(Pid, "打开app文件", v_app_file, Common.Rnok);
                                    break;
                                }
                            }
                            //
                            appbuf = new byte[v_applength + 10];
                            v_applength = 0;
                            if (".bin".equals(v_appname.substring(v_appname.length() - 4)) || ".BIN".equals(v_appname.substring(v_appname.length() - 4))) {
                                try {
                                    v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                                    //v_applength = 0x0B8356;
                                    v_app_block[0] = v_applength;
                                    v_app_block[1] = v_applength;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    ShowProcessList(Pid, "解析app文件", v_appname, Common.Rnok);
                                    break;
                                }
                            }
                            if (v_applength < 100) {
                                ShowProcessList(Pid, "App数据解析", "失败", Common.Rnok);
                                break;
                            }
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x02) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.CX62B_7DCT_seedToKey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 14) //开始下载驱动
                    {
                        if (v_drilength < 10) //无需下载驱动
                        {
                            i += 3;
                            continue;
                        } else //下载驱动,驱动暂时按单块处理,FLR也是多块
                        {
                            if (v_dri_down_block < v_dri_block[0]) {
                                System.arraycopy(v_dri_adr, 1 + 4 * v_dri_down_block, cmd, 4, 4);
                                v_dri_len[0] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 24) & 0xFF);
                                v_dri_len[1] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 16) & 0xFF);
                                v_dri_len[2] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 8) & 0xFF);
                                v_dri_len[3] = (byte) ((v_dri_block[1 + v_dri_down_block] >>> 0) & 0xFF);
                                v_dri_down_length += v_dri_block[1 + v_dri_down_block];
                                System.arraycopy(v_dri_len, 0, cmd, 8, 4);
                            }
                        }
                    } else if (i == 15) //下载驱动
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_dri_down < v_dri_down_length) {
                            if ((v_dri_down + v_maxlen - 2) >= v_dri_down_length) //last
                            {
                                v_len = v_dri_down_length - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                        v_dri_down_block++;
                    } else if (i == 17) //检查有效性
                    {
                        System.arraycopy(v_dri_adr, 1, cmd, 5, 4);
                    } else if (i == 19) //擦除APP,按多个块处理
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 5, 4);
                        v_app_len[0] = 0x00;
                        v_app_len[1] = 0x54;
                        v_app_len[2] = (byte) 0x80;
                        v_app_len[3] = 0x00;
                        System.arraycopy(v_app_len, 0, cmd, 9, 4);
                    } else if (i == 20) //请求下载APP
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 4, 4);
                        v_app_len[0] = (byte) ((v_applength >>> 24) & 0xFF);
                        v_app_len[1] = (byte) ((v_applength >>> 16) & 0xFF);
                        v_app_len[2] = (byte) ((v_applength >>> 8) & 0xFF);
                        v_app_len[3] = (byte) ((v_applength >>> 0) & 0xFF);
                        System.arraycopy(v_app_len, 0, cmd, 8, 4);
                        v_down_length = v_applength;
                    } else if (i == 21) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data_process)+ ":" + (v_app_down * 100 / v_applength) + " %");
                        }
                        v_down_block++;
                    }

                    //特殊处理多次发送命令
                    if (i == 15 || i == 21) {

                    } else if (i == 7 || i == 8 || i == 9 || i == 25 || i == 26 || i == 27) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {

                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 28 || i == 29 || i == 30) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                            case 0xF195:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 16) //结束下载driver
                    {
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (i == 22) //结束下载app
                    {
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x01) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            //ShowProcessList(Pid,step_name,"",Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        Sleep(1000);
                    } else {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65PHEV_TcuFlash3(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int vPid = Integer.valueOf(Pstep.get("MODULE_ID"));
            int Pid = vPid;
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int v_maxlen = 0;
            short[] v_crc = new short[3];
            v_crc[0] = (short) 0xFFFF;
            v_crc[1] = (short) 0xFFFF;
            int[] canid = new int[2];
            if (Common.cartype.tcu_file_len != 0x400) {
                ShowProcessList(num, "TCU", "标定文件未下载!", Common.Rnok);
                return;
            }
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            String v_drivername = Pstep.get("DRIVER");
            Common.cartype.mesinfo.flash_tcu = Pstep.get("FILE");
            if (Common.cartype.mesinfo.flash_tcu == null) {
                ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                return;
            }

            String v_partnumber = "";
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            //int v_drilen = 0;
            byte[] v_dri_adr = new byte[256];
            byte[] v_dri_len = new byte[4];
            int[] v_dri_block = new int[10];
            int v_drilength = 0;
            byte[] v_app_adr = new byte[512];
            byte[] v_app_len = new byte[4];
            int[] v_app_block = new int[100];
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_block = 0;  //块数
            int v_down_length = 0;
            int v_app_down = 0;
            int v_app_startadr = 0; //
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid = vPid + i;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 3) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_tcu == null) {
                            ShowProcessList(Pid, "解析TCU文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        }
                        v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + v_drivername;
                        ShowProcessList(Pid, "驱动文件:", v_dri_file, Common.Rok);
                        if ((v_drivername != null) && (v_drivername.length() > 5)) {
                            if (".bin".equals(v_drivername.substring(v_drivername.length() - 4))) {
                                try {
                                    v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                    v_dri_adr[0] = 0x60;
                                    v_dri_adr[1] = 0x00;
                                    v_dri_adr[2] = 0x00;
                                    v_dri_adr[3] = 0x00;
                                    v_dri_adr[4] = 0x00;
                                    v_dri_adr[5] = 0x01;
                                    v_dri_adr[6] = 0x00;
                                    v_dri_adr[7] = 0x00;
                                    v_dri_block[0] = 1;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_drilength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                    ShowProcessList(Pid, "打开Driver文件", v_drivername, Common.Rnok);
                                    break;
                                }
                                //
                                dribuf = new byte[v_drilength + 10];
                                if (".bin".equals(v_drivername.substring(v_drivername.length() - 4)))
                                    try {
                                        v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                        v_drilength = 0;
                                        ShowProcessList(Pid, "解析Driver文件", v_drivername, Common.Rnok);
                                        break;
                                    }

                                if (v_drilength <= 10) {
                                    ShowProcessList(Pid, "Driver数据解析", v_drivername, Common.Rnok);
                                    break;
                                }
                            }
                        }
                        ShowFuncTip("解析app文件...");

                        //String v_appname ="01.00.01.bin";
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/TCU/" + Common.cartype.mesinfo.flash_tcu;
                        ShowProcessList(Pid, "flash文件:", v_app_file, Common.Rok);
                        if ((Common.cartype.mesinfo.flash_tcu != null) && (Common.cartype.mesinfo.flash_tcu.length() > 5)) {
                            if (".hex".equals(Common.cartype.mesinfo.flash_tcu.substring(Common.cartype.mesinfo.flash_tcu.length() - 4)) || ".HEX".equals(Common.cartype.mesinfo.flash_tcu.substring(Common.cartype.mesinfo.flash_tcu.length() - 4))) {
                                try {
                                    //v_applength = Commonfunc.GetBinFileLength(v_app_file);
                                    v_applength = Commonfunc.GetHexFileLength(v_app_file, v_app_adr, (long) 0x80040000);
                                    //v_applength -= 0x30;
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    v_applength = 0;
                                    m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                                    ShowProcessList(Pid, "打开app文件", v_app_file, Common.Rnok);
                                    break;
                                }
                            }
                            //
                            appbuf = new byte[v_applength + 10];
                            v_applength = 0;
                            if (".hex".equals(Common.cartype.mesinfo.flash_tcu.substring(Common.cartype.mesinfo.flash_tcu.length() - 4)) || ".HEX".equals(Common.cartype.mesinfo.flash_tcu.substring(Common.cartype.mesinfo.flash_tcu.length() - 4))) {
                                try {
                                    //v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                                    v_applength = Commonfunc.ReadHexFile(v_app_file, appbuf, v_app_block, (long) 0x80040000);
                                    //v_applength -= 0x30;
                                    v_app_adr[0] = 6; //块数,增加标定文件
                                    v_down_block = 0;
                                    v_block = 6;//块数,增加标定文件
                                    //System.arraycopy(appbuf, 16, v_app_adr, 1, 4);
                                    //System.arraycopy(appbuf, 32, v_app_adr, 5, 4);
                                    //v_app_block[0] = ((appbuf[16 + 12]&0xFF) << 24) + ((appbuf[16 + 13]&0xFF) << 16) + ((appbuf[16 + 14]&0xFF) << 8) + (appbuf[16 + 15]&0xFF) ;
                                    //v_app_block[1] = ((appbuf[32 + 12]&0xFF) << 24) + ((appbuf[32 + 13]&0xFF) << 16) + ((appbuf[32 + 14]&0xFF) << 8) + (appbuf[32 + 15]&0xFF) ;
                                    //crc
                                    //int v_start = 0x30 + 0x200;
                                    //v_crc[0] = Commonfunc.me1781_CalcCRC16(appbuf, v_start, v_app_block[0], (short) 0xFFFF);
                                    //v_start += 0x200000;
                                    //v_crc[1] = Commonfunc.me1781_CalcCRC16(appbuf, v_start, v_app_block[1], (short) 0xFFFF);
                                    //v_crc[2] = Commonfunc.me1781_CalcCRC16(appbuf, v_start, v_app_block[1],v_crc[0]);
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    ShowProcessList(Pid, "解析app文件", Common.cartype.mesinfo.flash_tcu, Common.Rnok);
                                    break;
                                }
                            }
                            if (v_applength < 100) {
                                ShowProcessList(Pid, "App数据解析", "失败", Common.Rnok);
                                break;
                            }
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.hefei_BCM_safekey(seed, key);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 9) //开始下载驱动
                    {
                        if (v_drilength < 10) //无需下载驱动
                        {
                            i += 2;
                            continue;
                        } else //下载驱动
                        {
                            if (v_dri_down_block < v_dri_block[0]) {
                                System.arraycopy(v_dri_adr, 1 + 4 * v_dri_down_block, cmd, 4, 4);
                                v_dri_down_length = ((v_dri_adr[4] & 0xFF) << 24) + ((v_dri_adr[5] & 0xFF) << 16) + ((v_dri_adr[6] & 0xFF) << 8) + (v_dri_adr[7] & 0xFF);
                                System.arraycopy(v_dri_adr, 0, cmd, 4, 8);
                            }
                        }
                    } else if (i == 10) //下载驱动
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_dri_down < v_dri_down_length) {
                            if ((v_dri_down + v_maxlen - 2) >= v_dri_down_length) //last
                            {
                                v_len = v_dri_down_length - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                        v_dri_down_block++;
                    } else if (i == 12) //擦除APP,按多个块处理
                    {
                        v_app_down = 0;
                        if (v_down_block == 0) {
                            v_app_startadr = 0x100000;
                            v_down_length = 0x100000;
                            byte[] adr = {(byte) 0x80, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 5, 8);
                        } else if (v_down_block == 1) {
                            v_app_startadr = 0x204000;
                            v_down_length = 0x13C000;
                            byte[] adr = {(byte) 0x80, 0x20, 0x40, 0x00, 0x00, 0x13, (byte) 0xC0, 0x00};
                            System.arraycopy(adr, 0, cmd, 5, 8);
                        } else if (v_down_block == 2) {
                            v_app_startadr = 0x080000;
                            v_down_length = 0x080000;
                            byte[] adr = {(byte) 0x80, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 5, 8);
                        } else if (v_down_block == 3) {
                            v_app_startadr = 0x040000;
                            v_down_length = 0x020000;
                            byte[] adr = {(byte) 0x80, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 5, 8);
                        } else if (v_down_block == 4) {
                            v_app_startadr = 0x340000;
                            v_down_length = 0x0C0000;
                            byte[] adr = {(byte) 0x80, 0x34, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 5, 8);
                        } else if (v_down_block == 5) //增加标定文件
                        {
                            if (Common.cartype.tcu_file_len != 0x400) {
                                ShowProcessList(Pid, "标定数据", "获取标定数据失败!", Common.Rnok);
                                i += 5;
                                continue;
                            }
                            v_app_startadr = 0;
                            v_down_length = Common.cartype.tcu_file_len;
                            byte[] adr = {(byte) 0x80, 0x01, (byte) 0x80, 0x00, 0x00, 0x00, 0x40, 0x00};
                            System.arraycopy(adr, 0, cmd, 5, 8);
                        }
                    } else if (i == 15) //请求下载APP
                    {
                        if (v_down_block == 0) {
                            byte[] adr = {(byte) 0x80, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 4, 8);
                        } else if (v_down_block == 1) {
                            byte[] adr = {(byte) 0x80, 0x20, 0x40, 0x00, 0x00, 0x13, (byte) 0xC0, 0x00};
                            System.arraycopy(adr, 0, cmd, 4, 8);
                        } else if (v_down_block == 2) {
                            byte[] adr = {(byte) 0x80, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 4, 8);
                        } else if (v_down_block == 3) {
                            byte[] adr = {(byte) 0x80, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 4, 8);
                        } else if (v_down_block == 4) {
                            byte[] adr = {(byte) 0x80, 0x34, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00};
                            System.arraycopy(adr, 0, cmd, 4, 8);
                        } else if (v_down_block == 5) {
                            byte[] adr = {(byte) 0x80, 0x01, (byte) 0x80, 0x00, 0x00, 0x00, 0x40, 0x00};
                            System.arraycopy(adr, 0, cmd, 4, 8);
                        }
                        //v_down_length = ( (appbuf[16 + v_down_block * 16 + 12]&0xFF) << 24) + ( (appbuf[16 + v_down_block * 16 + 13]&0xFF) << 16)+ ( (appbuf[16 + v_down_block * 16 + 14]&0xFF) << 8) + (appbuf[16 + v_down_block * 16 + 15]&0xFF) ;;
                    } else if (i == 16) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            if (v_down_block == 5)
                                System.arraycopy(Common.cartype.tcu_file, v_app_startadr + v_app_down, cmd_down, v_start, v_len);
                            else
                                System.arraycopy(appbuf, v_app_startadr + v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data_process)+ ":" + (v_app_down * 100 / v_down_length) + " %");
                        }
                        v_down_block++;
                    } else if (i == 18) //检查有效性
                    {

                    } else if (i == 21) //检查有效性2
                    {
                        //System.arraycopy(v_dri_adr, 1, cmd, 5, 4);
                        //cmd[5] = (byte) ((v_crc[2] >> 8) & 0xFF);
                        //cmd[6] = (byte) (v_crc[2] & 0xFF);
                    }
                    //特殊处理多次发送命令
                    if (i == 10 || i == 16) {

                    } else if (i == 3 || i == 4 || i == 5 || i == 25 || i == 26 || i == 27) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 5) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            if (i < 5) continue;
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    }
                    //else
                    //	ShowProcessListHide(Pid,step_name,Commonfunc.bytesToHexString(Readbuf, 0,Readbuf[0]+1),Common.Rok);
                    //特殊处理返回结果
                    if (i == 28 || i == 29 || i == 30) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF195:
                            case 0xF193:
                            case 0xF191:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_partnumber = v_show;
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 17) //结束下载driver
                    {
                        if (v_down_block < v_block)
                            i -= 6;
                        ShowProcessList(Pid, step_name, "结束刷写区域:" + v_down_block, Common.Rok);
                    } else if (i == 22) //结束下载app
                    {
                        //ShowProcessList(Pid,step_name,"",Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            //ShowProcessList(Pid,step_name,"",Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x02 && (Readbuf[3] & 0xFF) == 0xFF && Readbuf[4] == 0x00) //擦除
                    {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        v_down_block++;
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            i -= 3;
                        } else
                            v_down_block = 0;
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x02 && (Readbuf[3] & 0xFF) == 0xFF && Readbuf[4] == 0x01) //crc
                    {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                        v_down_block++;
                        if (v_down_block < (v_app_adr[0] & 0xFF)) {
                            i -= 3;
                        }
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_FrmFlash1(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            byte[] frmdata = null;
            if (Common.cartype.mesinfo.flash_frm != null) {
                frmdata = CommonXml.ReadFrmXmlFile(Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/FRM/" + Common.cartype.mesinfo.flash_frm);
                if (frmdata == null) {
                    m_com.m_log.PrintLog("Open File Fialed:" + Common.cartype.mesinfo.flash_frm);
                    ShowProcessList(Pid, "解析FRM文件", "打开文件失败:" + Common.cartype.mesinfo.flash_frm, Common.Rnok);
                    return;
                }
            } else {
                ShowProcessList(Pid, "解析FRM文件", "Mes推送数据为空", Common.Rnok);
                return;
            }
            //SetCanInitTimer(0);
            byte[] cmd_down = null;
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_JX65_Safekey(seed, key, Pmodule);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        cmdlen = frmdata.length + 3;
                        cmd_down = new byte[cmdlen + 2];
                        //拷贝数据
                        cmd_down[0] = (byte) ((cmdlen) / 0x100);
                        cmd_down[1] = (byte) ((cmdlen) % 0x100);
                        cmd_down[2] = 0x2E;
                        cmd_down[3] = 0x4F;
                        cmd_down[4] = (byte) 0x8E;
                        System.arraycopy(frmdata, 0, cmd_down, 5, frmdata.length);
                        cmdlen += 2;
                    }

                    //特殊处理多次发送命令
                    if (i == 5) {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 1);
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                        break;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                        return;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    }

                    //特殊处理返回结果
                    if ((Readbuf[1] == 0x62) && ((Readbuf[2] & 0xFF) == 0xF1) && (((Readbuf[3] & 0xFF) == 0x88) || ((Readbuf[3] & 0xFF) == 0xC0))) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        //String v_getsoft = Common.cartype.getModuleStr(Pname,partnumber_cache, "appFileVersionLatest");
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                            default:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_FcmFlash1(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int v_maxlen = 0;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            if (Common.cartype.mesinfo.flash_fcm == null) {
                ShowProcessList(Pid, "解析FCM文件", "Mes推送数据为空", Common.Rnok);
                return;
            }
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] dribuf = null;
            byte[] v_dri_adr = new byte[256];
            byte[] v_dri_len = new byte[4];
            int[] v_dri_block = new int[10];
            int v_drilength = 0;
            byte[] appbuf = null;
            byte[] v_app_adr = new byte[512];
            byte[] v_app_len = new byte[4];
            int[] v_app_block = new int[100];
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 5) {
                        //先解析driver文件
                        ShowFuncTip("解析FCM driver文件...");
                        v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/FCM/" + "flashdriverV01.s19";
                        try {
                            v_drilength = Commonfunc.GetS19FileLength(v_dri_file, v_dri_adr);
                            dribuf = new byte[v_drilength + 10];
                            v_drilength = Commonfunc.ReadS19File(v_dri_file, dribuf, 0, v_dri_block);

                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        //解析app文件
                        ShowFuncTip("解析FCM app文件...");
                        if (Common.cartype.mesinfo.flash_fcm == null) {
                            ShowProcessList(Pid, "解析FCM文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        }
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/FCM/" + Common.cartype.mesinfo.flash_fcm;
                        try {
                            v_applength = Commonfunc.GetS19FileLength(v_app_file, v_app_adr);
                            appbuf = new byte[v_applength + 10];
                            v_applength = Commonfunc.ReadS19File(v_app_file, appbuf, 0, v_app_block);

                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (v_applength < 10) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "解析FCM文件", "打开文件失败:" + Common.cartype.mesinfo.flash_fcm, Common.Rnok);
                            return;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Chery_JX65_Safekey(seed,key,Pmodule);
                        EolFunction.Cx62B_FCM_Level2(seed, key, 0x5400);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 8) //开始下载驱动
                    {
                        v_dri_down_length = 0x80;
                    } else if (i == 9) //下载驱动
                    {
                        v_maxlen = 0x80;
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_dri_down < v_dri_down_length) {
                            if ((v_dri_down + v_maxlen - 2) >= v_dri_down_length) //last
                            {
                                v_len = v_dri_down_length - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                        v_dri_down_block++;
                    } else if (i == 11) //擦除APP,按多个块处理
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 5, 4);
                        v_app_len[0] = (byte) ((v_applength >>> 24) & 0xFF);
                        v_app_len[1] = (byte) ((v_applength >>> 16) & 0xFF);
                        v_app_len[2] = (byte) ((v_applength >>> 8) & 0xFF);
                        v_app_len[3] = (byte) ((v_applength >>> 0) & 0xFF);
                        System.arraycopy(v_app_len, 0, cmd, 9, 4);
                    } else if (i == 14) //请求下载APP
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 4, 4);
                        v_app_len[0] = (byte) ((v_applength >>> 24) & 0xFF);
                        v_app_len[1] = (byte) ((v_applength >>> 16) & 0xFF);
                        v_app_len[2] = (byte) ((v_applength >>> 8) & 0xFF);
                        v_app_len[3] = (byte) ((v_applength >>> 0) & 0xFF);
                        System.arraycopy(v_app_len, 0, cmd, 8, 4);
                        v_down_length = v_applength;
                    } else if (i == 15) //下载数据
                    {
                        v_maxlen = 0x400;
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_applength + "\\" + v_app_down);
                        }
                        v_down_block++;
                    }

                    //特殊处理多次发送命令
                    if (cmd[1] == 0x36) {

                    } else if (i == 1 || i == 2 || i == 3 || i == 4) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        //Sleep(50);
                        //m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 9) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 9) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (cmd[1] == 0x22) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (cmd[1] == 0x37) //结束下载
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65PHEV_FcmFlash1(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[4];
            byte[] key = new byte[4];
            int v_maxlen = 0;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            //先从配置文件找
            String v_drifile = Pstep.get("DRIVER");
            if (Common.cartype.mesinfo.flash_fcm == null) {
                //ShowProcessList(Pid,"解析FCM文件","Mes推送数据为空",Common.Rnok);
                m_com.m_log.PrintLog("解析FCM文件:" + "Mes推送数据为空");
                Common.cartype.mesinfo.flash_fcm = Pstep.get("FILE");
                //return;
            } else {
                ShowProcessList(Pid, "驱动文件:", v_drifile, Common.Rok);
                ShowProcessList(Pid, "应用文件:", Common.cartype.mesinfo.flash_fcm, Common.Rok);
            }
            m_com.m_log.PrintLog("驱动文件:" + v_drifile);
            m_com.m_log.PrintLog("应用文件:" + Common.cartype.mesinfo.flash_fcm);
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] dribuf = null;
            byte[] v_dri_adr = new byte[256];
            byte[] v_dri_len = new byte[4];
            int[] v_dri_block = new int[10];
            int v_drilength = 0;
            byte[] appbuf = null;
            byte[] v_app_adr = new byte[512];
            byte[] v_app_len = new byte[4];
            int[] v_app_block = new int[100];
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            byte[] crc_code = new byte[4];
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 5) {
                        //先解析driver文件
                        ShowFuncTip("解析FCM driver文件...");
                        v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/FCM/" + "FlashDriver.s19";
                        try {
                            v_drilength = Commonfunc.GetS19FileLength(v_dri_file, v_dri_adr);
                            dribuf = new byte[v_drilength + 10];
                            v_drilength = Commonfunc.ReadS19File(v_dri_file, dribuf, 0, v_dri_block);

                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            m_com.m_log.PrintLog(e.toString());
                        }
                        //解析app文件
                        ShowFuncTip("解析FCM app文件...");
                        if (Common.cartype.mesinfo.flash_fcm == null) {
                            ShowProcessList(Pid, "解析FCM文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        }
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/FCM/" + Common.cartype.mesinfo.flash_fcm;
                        try {
                            v_applength = Commonfunc.GetS19FileLength(v_app_file, v_app_adr);
                            appbuf = new byte[v_applength + 10];
                            v_applength = Commonfunc.ReadS19File(v_app_file, appbuf, 0, v_app_block);
                            EolFunction.CalcCRC(appbuf, v_applength, crc_code);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            m_com.m_log.PrintLog(e.toString());
                        }
                        if (v_applength < 10) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "解析FCM文件", "打开文件失败:" + Common.cartype.mesinfo.flash_fcm, Common.Rnok);
                            return;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Chery_JX65_Safekey(seed,key,Pmodule);
                        EolFunction.Cx62B_FCM_Level2(seed, key, 0x5400);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 8) //开始下载驱动
                    {
                        v_dri_down_length = v_drilength;
                    } else if (i == 9) //下载驱动
                    {
                        v_maxlen = 0xFE2;
                        ;
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        while (v_dri_down < v_dri_down_length) {
                            if ((v_dri_down + v_maxlen - 2) >= v_dri_down_length) //last
                            {
                                v_len = v_dri_down_length - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                        v_dri_down_block++;
                    } else if (i == 11) //擦除APP,按多个块处理
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 5, 4);
                        v_app_len[0] = (byte) ((v_applength >>> 24) & 0xFF);
                        v_app_len[1] = (byte) ((v_applength >>> 16) & 0xFF);
                        v_app_len[2] = (byte) ((v_applength >>> 8) & 0xFF);
                        v_app_len[3] = (byte) ((v_applength >>> 0) & 0xFF);
                        System.arraycopy(v_app_len, 0, cmd, 9, 4);
                    } else if (i == 14) //请求下载APP
                    {
                        System.arraycopy(v_app_adr, 1 + 4 * v_down_block, cmd, 4, 4);
                        v_app_len[0] = (byte) ((v_applength >>> 24) & 0xFF);
                        v_app_len[1] = (byte) ((v_applength >>> 16) & 0xFF);
                        v_app_len[2] = (byte) ((v_applength >>> 8) & 0xFF);
                        v_app_len[3] = (byte) ((v_applength >>> 0) & 0xFF);
                        System.arraycopy(v_app_len, 0, cmd, 8, 4);
                        v_down_length = v_applength;
                    } else if (i == 15) //下载数据
                    {
                        //v_maxlen = 0x400;
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_applength + "\\" + v_app_down);
                        }
                        v_down_block++;
                    } else if (cmd[1] == 0x31 && cmd[2] == 0x01 && (cmd[3] & 0xFF) == 0xDA && cmd[4] == 0x04) //crc
                    {
                        cmd[5] = crc_code[0];
                        cmd[6] = crc_code[1];
                    }

                    //特殊处理多次发送命令
                    if (cmd[1] == 0x36) {

                    } else if (i == 1 || i == 2 || i == 3 || i == 4) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        //Sleep(50);
                        //m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 9) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 9) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (cmd[1] == 0x22) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (cmd[1] == 0x37) //结束下载
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (i == 14) //请求下载
                    {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF) - 2;
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(3000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else {
                        //ShowProcessList(Pid,step_name, "",Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_Ems1781(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            if (Common.cartype.mesinfo.flash_ems == null) {
                ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空", Common.Rnok);
                return;
            }
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            //int v_drilen = 0;
            int v_drilength = 0;
            int v_applength = 0;
            int v_down_length = 0;
            int v_app_down = 0;
            int v_down_block = 0; //已经下载的块数
            //driver
            short v_calc = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 1) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_ems == null) {
                            ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        } else {
                            v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + "flashdrive.bin";
                            int ems_a = Common.cartype.mesinfo.flash_ems.indexOf("*", 20);
                            if (ems_a > 0) {
                                int ems_b = Common.cartype.mesinfo.flash_ems.indexOf("*", ems_a + 2);
                                String ems_name = Common.cartype.mesinfo.flash_ems.substring(ems_a + 1, ems_b);
                                v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + ems_name + ".bin";
                            }
                        }
                        if ((v_dri_file != null) && (v_dri_file.length() > 15)) {
                            try {
                                v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                //v_drilength = Commonfunc.GetHexFileLength(v_dri_file, v_dri_adr, (long) 0);;
                                dribuf = new byte[v_drilength + 10];
                                //v_drilength = Commonfunc.ReadHexFile(v_dri_file,dribuf, v_dri_block, (long) 0);
                                v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            if (v_drilength != 16) {
                                m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                ShowProcessList(Pid, "Driver数据解析", v_dri_file, Common.Rnok);
                                break;
                            }
                        }
                        ShowFuncTip("解析app文件...");
                        try {
                            //v_applength = Commonfunc.GetHexFileLength(v_app_file, v_app_adr, (long) 0);
                            v_applength = Commonfunc.GetBinFileLength(v_app_file);
                            appbuf = new byte[v_applength + 10];
                            //v_applength = Commonfunc.ReadHexFile(v_app_file, appbuf, v_app_block, (long) 0);
                            v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                            //v_applength = 0x240000;  //特殊处理
                            v_down_length = v_applength;
                            v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0, v_applength, (short) 0xffff);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (v_applength < 100) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "App数据解析", v_app_file, Common.Rnok);
                            break;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 8) //下载驱动
                    {
                        //拷贝数据
                        System.arraycopy(dribuf, 0, cmd, 3, v_drilength);
                    } else if (i == 14) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_applength + "\\" + v_app_down);
                        }
                        v_down_block++;
                    } else if (i == 16) {
                        cmd[13] = (byte) ((v_calc >> 8) & 0xFF);
                        cmd[14] = (byte) (v_calc & 0xFF);
                    } else if (i == 19) {
                        cmd[5] = (byte) ((v_calc >> 8) & 0xFF);
                        cmd[6] = (byte) (v_calc & 0xFF);
                    }

                    //特殊处理多次发送命令
                    if (i == 14) {

                    } else if (i == 1 || i == 2 || i == 3 || i == 23 || i == 24 || i == 25) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8 && (i != 22)) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 28 || i == 29 || i == 30) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 9) //结束下载driver
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (i == 15) //结束下载app
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_EmsUP8(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            String emsfile = "";
            if (Common.cartype.mesinfo.flash_ems == null) {
                ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空,使用缓存配置", Common.Rnull);
                //获取缓存数据
                emsfile = Pstep.get("Flash");
                if (emsfile == null) {
                    ShowProcessList(Pid, "解析EMS文件", "缓存配置为空", Common.Rnok);
                    return;
                }
            } else {
                int adr = Common.cartype.mesinfo.flash_ems.indexOf("FF*");
                if (adr > 0) {
                    emsfile = Common.cartype.mesinfo.flash_ems.substring(adr + 3);
                    adr = emsfile.indexOf("*");
                    if (adr > 0)
                        emsfile = emsfile.substring(0, adr);
                } else
                    emsfile = Common.cartype.mesinfo.flash_ems;
                if (emsfile.length() < 5) {
                    ShowProcessList(Pid, "解析EMS文件", "解析失败!", Common.Rnok);
                    return;
                }
            }
            SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            byte[] appbuf = null;
            int v_applength = 0;
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            short v_calc = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            byte[] cmd_exd = {0x02, 0x10, 0x03};
            byte[] cmd_stop = {0x02, (byte) 0x85, 0x02};
            byte[] cmd_stop1 = {0x03, 0x28, 0x03, 0x03};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 1) {
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + emsfile + ".bin";
                        m_com.m_log.PrintLog("App File:" + v_app_file);
                        ShowFuncTip("解析app文件...");
                        try {
                            //v_applength = Commonfunc.GetHexFileLength(v_app_file, v_app_adr, (long) 0);
                            v_applength = Commonfunc.GetBinFileLength(v_app_file);
                            appbuf = new byte[v_applength + 10];
                            //v_applength = Commonfunc.ReadHexFile(v_app_file, appbuf, v_app_block, (long) 0);
                            v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                            //v_applength = 0x240000;  //特殊处理
                            v_down_length = v_applength;
                            //v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0, v_applength,(short)0xffff);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (v_applength < 100) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "App数据解析", v_app_file, Common.Rnok);
                            break;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 13)  //请求下载
                    {
                        m_com.CanSendOneOnly(0x7DF, cmd_exd, cmd_exd[0] + 1);
                        Sleep(20);
                        m_com.CanSendOneOnly(0x7DF, cmd_stop, cmd_stop[0] + 1);
                        Sleep(20);
                        m_com.CanSendOneOnly(0x7DF, cmd_stop1, cmd_stop1[0] + 1);
                        Sleep(20);
                    } else if (i == 14) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_applength + "\\" + v_app_down);
                        }
                    }


                    //特殊处理多次发送命令
                    if (i == 14) {

                    } else if (i == 1 || i == 2 || i == 3) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8 && (i != 22)) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 22 || i == 23 || i == 24) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 15) //结束下载app
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(2000);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_EmsUD8(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            String emsfile = "";
            if (Common.cartype.mesinfo.flash_ems == null) {
                ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空,使用缓存配置", Common.Rnull);
                //获取缓存数据
                emsfile = Pstep.get("Flash");
                if (emsfile == null) {
                    ShowProcessList(Pid, "解析EMS文件", "缓存配置为空", Common.Rnok);
                    return;
                }
            } else {
                int adr = Common.cartype.mesinfo.flash_ems.indexOf("FF*");
                if (adr > 0) {
                    emsfile = Common.cartype.mesinfo.flash_ems.substring(adr + 3);
                    adr = emsfile.indexOf("*");
                    if (adr > 0)
                        emsfile = emsfile.substring(0, adr);
                } else
                    emsfile = Common.cartype.mesinfo.flash_ems;
                if (emsfile.length() < 5) {
                    ShowProcessList(Pid, "解析EMS文件", "解析失败!", Common.Rnok);
                    return;
                }
            }
            SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            byte[] appbuf = null;
            int v_applength = 0;
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            short v_calc = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            byte[] cmd_exd = {0x02, 0x10, 0x03};
            byte[] cmd_stop = {0x02, (byte) 0x85, 0x02};
            byte[] cmd_stop1 = {0x03, 0x28, 0x03, 0x03};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 1) {
                        v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + emsfile + ".bin";
                        m_com.m_log.PrintLog("App File:" + v_app_file);
                        ShowFuncTip("解析app文件...");
                        try {
                            //v_applength = Commonfunc.GetHexFileLength(v_app_file, v_app_adr, (long) 0);
                            v_applength = Commonfunc.GetBinFileLength(v_app_file);
                            appbuf = new byte[v_applength + 10];
                            //v_applength = Commonfunc.ReadHexFile(v_app_file, appbuf, v_app_block, (long) 0);
                            v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                            //v_applength = 0x240000;  //特殊处理
                            v_down_length = v_applength;
                            //v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0, v_applength,(short)0xffff);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (v_applength < 100) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "App数据解析", v_app_file, Common.Rnok);
                            break;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (i == 13)  //请求下载
                    {
                        //m_com.CanSendOneOnly(0x7DF, cmd_exd, cmd_exd[0] + 1);
                        //Sleep(20);
                        //m_com.CanSendOneOnly(0x7DF, cmd_stop, cmd_stop[0] + 1);
                        //Sleep(20);
                        //m_com.CanSendOneOnly(0x7DF, cmd_stop1, cmd_stop1[0] + 1);
                        //Sleep(20);
                        cmd[9] = (byte) (v_down_length / 0x10000);
                        cmd[10] = (byte) (v_down_length / 0x100);
                        cmd[11] = (byte) (v_down_length & 0xFF);
                    } else if (i == 14) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_applength + "\\" + v_app_down);
                        }
                    }


                    //特殊处理多次发送命令
                    if (i == 14) {

                    } else if (i == 1 || i == 2 || i == 3) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8 && (i != 22)) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 22 || i == 23 || i == 24) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 15) //结束下载app
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(2000);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65PHEV_Ems3(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            if (!m_com.SetCommunTimer(5, 2000, 5000, 1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            String v_drivername = Pstep.get("DRIVER");
            String v_appname = "";
            if (Common.cartype.mesinfo.flash_ems == null) {
                m_com.m_log.PrintLog("解析EMS文件:" + "Mes推送数据为空,使用本地配置文件.");
                v_appname = Pstep.get("FILE");
                if (v_appname == null || v_appname.length() < 5)  //按本地配置
                {
                    m_com.m_log.PrintLog("解析EMS文件:" + "本地未配置.");
                    return;
                }
            } else //解析MES信息
            {
                int addr = Common.cartype.mesinfo.flash_ems.indexOf("250000*");
                if (addr > 0)
                    v_appname = Common.cartype.mesinfo.flash_ems.substring(addr + 7);
                addr = v_appname.indexOf("*");
                if (addr > 0)
                    v_appname = v_appname.substring(0, addr);
                else
                    v_appname = "";
                if (v_appname.length() > 5) {
                    v_appname = v_appname + ".bin";
                } else {
                    m_com.m_log.PrintLog("解析EMS文件失败:" + Common.cartype.mesinfo.flash_ems);
                    return;
                }
            }
            ShowProcessList(Pid, "DriverName", v_drivername, Common.Rok);
            ShowProcessList(Pid, "AppFileName", v_appname, Common.Rok);
            m_com.m_log.PrintLog("DriverName:" + v_drivername);
            m_com.m_log.PrintLog("AppFileName:" + v_appname);
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            int v_drilen = 0;
            int v_dri_down = 0;
            int v_drilength = 0;
            int v_applength = 0;
            int v_down_length = 0;
            int v_app_down = 0;
            int v_down_block = 0; //已经下载的块数
            //driver
            short v_calc = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            byte[] cmd_exd = {0x02, 0x10, 0x03};
            byte[] cmd_stop = {0x02, (byte) 0x85, 0x02};
            byte[] cmd_stop1 = {0x03, 0x28, 0x03, 0x03};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 1) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_ems == null) {
                            ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空", Common.Rnok);
                            m_com.m_log.PrintLog("解析EMS文件:" + "Mes推送数据为空");
                            return;
                        } else {
                            v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + v_drivername;
                        }
                        m_com.m_log.PrintLog("DriverPathName:" + v_dri_file);
                        if ((v_dri_file != null) && (v_dri_file.length() > 15)) {
                            try {
                                v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                //v_drilength = Commonfunc.GetHexFileLength(v_dri_file, v_dri_adr, (long) 0);;
                                dribuf = new byte[v_drilength + 10];
                                //v_drilength = Commonfunc.ReadHexFile(v_dri_file,dribuf, v_dri_block, (long) 0);
                                v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                m_com.m_log.PrintLog(e.toString());
                            }
                            if (v_drilength <= 16) {
                                m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                ShowProcessList(Pid, "Driver数据解析", v_dri_file, Common.Rnok);
                                break;
                            }
                        }
                        ShowFuncTip("解析app文件...");
                        if (Common.cartype.mesinfo.flash_ems == null) {
                            ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空", Common.Rnok);
                            m_com.m_log.PrintLog("解析EMS文件:" + "Mes推送数据为空");
                            return;
                        } else {
                            v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + v_appname;
                        }
                        m_com.m_log.PrintLog("AppPathName:" + v_app_file);
                        try {
                            //v_applength = Commonfunc.GetHexFileLength(v_app_file, v_app_adr, (long) 0);
                            v_applength = Commonfunc.GetBinFileLength(v_app_file);
                            appbuf = new byte[v_applength + 10];
                            //v_applength = Commonfunc.ReadHexFile(v_app_file, appbuf, v_app_block, (long) 0);
                            v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                            //v_applength = 0x240000;  //特殊处理
                            v_down_length = v_applength;
                            //v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0, v_applength,(short)0xffff);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            m_com.m_log.PrintLog(e.toString());
                        }
                        if (v_applength < 100) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "App数据解析", v_app_file, Common.Rnok);
                            break;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 8) //下载驱动
                    {
                        //v_maxlen = 0xFFD;
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        v_dri_down = 0;
                        while (v_dri_down < v_drilength) {
                            if ((v_dri_down + v_maxlen - 2) >= v_drilength) //last
                            {
                                v_len = v_drilength - v_dri_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(dribuf, v_dri_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_dri_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_drilength + "\\" + v_dri_down);
                        }
                    } else if (i == 13)  //请求下载
                    {
                        m_com.CanSendOneOnly(0x7DF, cmd_exd, cmd_exd[0] + 1);
                        Sleep(20);
                        m_com.CanSendOneOnly(0x7DF, cmd_stop, cmd_stop[0] + 1);
                        Sleep(20);
                        m_com.CanSendOneOnly(0x7DF, cmd_stop1, cmd_stop1[0] + 1);
                        Sleep(20);
                    } else if (i == 14) //下载数据
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data) + ":" + v_applength + "\\" + v_app_down);
                        }
                        v_down_block++;
                    } else if (i == 16) {
                        //cmd[13] = (byte) ((v_calc >> 8) & 0xFF);
                        //cmd[14] = (byte) (v_calc & 0xFF);
                    } else if (i == 19) {
                        //cmd[5] = (byte) ((v_calc >> 8) & 0xFF);
                        //cmd[6] = (byte) (v_calc & 0xFF);
                    }

                    //特殊处理多次发送命令
                    if (i == 14 || i == 8) {

                    } else if (i == 1 || i == 2 || i == 3 || i == 23 || i == 24 || i == 25) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8 && (i != 22)) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 28 || i == 29 || i == 30) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 9) //结束下载driver
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (i == 15) //结束下载app
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03 && Readbuf[4] == 0x00) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(3000);
                    } else {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    }
                }
            }
        }

        private void fun_JX65_Ems1788(Profile.Section Pstep, String Pname) {
            int num = Integer.valueOf(Pstep.get("NUM"));
            int Pid = Integer.valueOf(Pstep.get("MODULE_ID"));
            String Pmodule = Pstep.get("MODULE");
            String step_t = null;
            String step_name = null;
            byte[] Readbuf = new byte[512];
            byte[] seed = new byte[10];
            byte[] key = new byte[10];
            int v_maxlen = 0;
            short v_crc = (short) 0xFFFF;
            int[] canid = new int[2];
            if (!SetCanInitial_Flash(Common.cartype.cartype, Pmodule, canid)) {
                ShowProcessList(num, "设置", "设置波特率", Common.Rnok);
                return;
            }
            if (!m_com.SetCanMode(1)) {
                ShowProcessList(num, "设置", "设置CanMode", Common.Rnok);
                return;
            }
            if (Common.cartype.mesinfo.flash_ems == null) {
                ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空", Common.Rnok);
                return;
            }
            //SetCanInitTimer(0);
            //先解析刷写数据
            String v_app_file = "";
            String v_dri_file = "";
            byte[] appbuf = null;
            //int v_applen = 0;
            byte[] dribuf = null;
            //int v_drilen = 0;
            int v_drilength = 0;
            int v_applength = 0;
            int v_down_block = 0; //已经下载的块数
            int v_down_length = 0;
            int v_app_down = 0;
            //driver
            int v_dri_down_block = 0;
            int v_dri_down_length = 0;
            int v_dri_down = 0;
            short v_calc = 0;
            byte[] cmd_link = {0x02, 0x3e, (byte) 0x80};
            int error = 0;
            for (int i = 1; i < (num + 1); i++) {
                Pid += 1;
                step_t = Pstep.get("T" + i);
                step_name = Pstep.get("T" + i + "_NAME");
                if (step_t == null) break;
                if (step_t.length() < 3) continue;
                if (step_t.substring(0, 3).equals("CMD"))  //cmd
                {
                    //获取cmd长度
                    int cmdlen = Commonfunc.HexStringtoInt(step_t.substring(4, 6)) + 1;
                    byte[] cmd = new byte[cmdlen];
                    if (Commonfunc.CmdStringToBytes(step_t.substring(4), cmd, cmdlen) != cmd.length)
                        return;
                    ShowFuncTip(step_name + "...");
                    //---------------------发送前处理---------------------
                    //解析下载文件
                    if (i == 1) {
                        //先解析driver文件
                        ShowFuncTip("解析Driver文件...");
                        if (Common.cartype.mesinfo.flash_ems == null) {
                            ShowProcessList(Pid, "解析EMS文件", "Mes推送数据为空", Common.Rnok);
                            return;
                        } else {
                            v_dri_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + "flashdrive.bin";
                            int ems_a = Common.cartype.mesinfo.flash_ems.indexOf("*", 20);
                            if (ems_a > 0) {
                                int ems_b = Common.cartype.mesinfo.flash_ems.indexOf("*", ems_a + 2);
                                String ems_name = Common.cartype.mesinfo.flash_ems.substring(ems_a + 1, ems_b);
                                v_app_file = Common.Dir + Common.GuestName + "/" + Common.cartype.carmode_dir + "/EMS/" + ems_name + ".bin";
                            }
                        }
                        if ((v_dri_file != null) && (v_dri_file.length() > 15)) {
                            try {
                                v_drilength = Commonfunc.GetBinFileLength(v_dri_file);
                                //v_drilength = Commonfunc.GetHexFileLength(v_dri_file, v_dri_adr, (long) 0);;
                                dribuf = new byte[v_drilength + 10];
                                //v_drilength = Commonfunc.ReadHexFile(v_dri_file,dribuf, v_dri_block, (long) 0);
                                v_drilength = Commonfunc.ReadBinFile(v_dri_file, dribuf);
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            if (v_drilength != 16) {
                                m_com.m_log.PrintLog("Open File Fialed:" + v_dri_file);
                                ShowProcessList(Pid, "Driver数据解析", v_dri_file, Common.Rnok);
                                break;
                            }
                        }
                        ShowFuncTip("解析app文件...");
                        try {
                            //v_applength = Commonfunc.GetHexFileLength(v_app_file, v_app_adr, (long) 0);
                            v_applength = Commonfunc.GetBinFileLength(v_app_file);
                            appbuf = new byte[v_applength + 10];
                            //v_applength = Commonfunc.ReadHexFile(v_app_file, appbuf, v_app_block, (long) 0);
                            v_applength = Commonfunc.ReadBinFile(v_app_file, appbuf);
                            //v_applength = 0x240000;  //特殊处理
                            v_down_length = v_applength;
                            if (v_down_length != 0x180000) {
                                ShowProcessList(Pid, "App数据解析", v_app_file, Common.Rnok);
                                break;
                            }
                            //v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0, v_applength);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (v_applength < 100) {
                            m_com.m_log.PrintLog("Open File Fialed:" + v_app_file);
                            ShowProcessList(Pid, "App数据解析", v_app_file, Common.Rnok);
                            break;
                        }
                    } else if (cmd[1] == 0x27 && cmd[2] == 0x04) //安全认证
                    {
                        if ((seed[0] | seed[1] | seed[2] | seed[3]) == 0) continue;
                        //EolFunction.Changan_SafeCode_level(seed,key,0x61E47D07);
                        EolFunction.Chery_IMMO_safekey(seed, key, 0);
                        System.arraycopy(key, 0, cmd, 3, cmd[0] - 2);
                    } else if (cmd[1] == 0x2E) //写
                    {
                        int v_code = (cmd[2] & 0xFF) * 0x100 + (cmd[3] & 0xFF);
                        switch (v_code) {
                            case 0xF199:
                                System.arraycopy(Common.cartype.time, 0, cmd, 4, cmd[0] - 3);
                                break;
                        }
                    } else if (i == 9) //下载驱动
                    {
                        //拷贝数据
                        System.arraycopy(dribuf, 0, cmd, 3, v_drilength);
                    } else if (i == 18) //下载数据区1
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        int v_adr = 0xC000;
                        v_down_length = 0x4000;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_adr + v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data_zone) + "1:" + v_applength + "\\" + v_app_down);
                        }
                        v_down_block++;
                    } else if (i == 21) //下载数据区2
                    {
                        byte[] cmd_down = new byte[v_maxlen + 2];
                        int v_len = 0;
                        int v_start = 0;
                        int v_frame = 1;
                        int v_adr = 0x20000;
                        v_down_length = 0x160000;
                        v_app_down = 0;
                        while (v_app_down < v_down_length) {
                            if ((v_app_down + v_maxlen - 2) >= v_down_length) //last
                            {
                                v_len = v_down_length - v_app_down;
                            } else {
                                v_len = v_maxlen - 2;
                            }
                            if ((v_len + 2) >= 0x100) {
                                v_start = 1;
                                cmd_down[0] = (byte) ((v_len + 2) / 0x100);
                            } else
                                v_start = 0;
                            //拷贝数据
                            cmd_down[v_start++] = (byte) ((v_len + 2) % 0x100);
                            cmd_down[v_start++] = 0x36;
                            cmd_down[v_start++] = (byte) (v_frame++);
                            System.arraycopy(appbuf, v_adr + v_app_down, cmd_down, v_start, v_len);

                            error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd_down, v_len + v_start, Readbuf, 5003, Common.cmdmaxtime * 3, 1);
                            if ((error > 100) || ((Readbuf[1] & 0xFF) == 0x7F))//异常
                            {
                                break;
                            }
                            Sleep(5);
                            m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                            v_app_down += v_len;
                            ShowFuncTip(getResources().getString(R.string.download_data_zone) + "2:" + v_applength + "\\" + v_app_down);
                        }
                        v_down_block++;
                    } else if (i == 23) {
                        v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0xC000, 0x4000, (short) 0xffff);
                        cmd[13] = (byte) ((v_calc >> 8) & 0xFF);
                        cmd[14] = (byte) (v_calc & 0xFF);
                    } else if (i == 26) {
                        v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0x20000, 0x160000, (short) 0xffff);
                        cmd[13] = (byte) ((v_calc >> 8) & 0xFF);
                        cmd[14] = (byte) (v_calc & 0xFF);
                    } else if (i == 29) {
                        v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0xC000, 0x4000, (short) 0xffff);
                        v_calc = Commonfunc.me1781_CalcCRC16(appbuf, 0x20000, 0x160000, v_calc);
                        cmd[5] = (byte) ((v_calc >> 8) & 0xFF);
                        cmd[6] = (byte) (v_calc & 0xFF);
                    }

                    //特殊处理多次发送命令
                    if (i == 18 || i == 21) {

                    } else if (i == 1 || i == 2 || i == 3) {
                        error = m_com.CanSendOneOnly(0x7DF, cmd, cmdlen);
                        Sleep(Common.waittime);
                        continue;
                    } else //普通发送命令
                    {
                        error = m_com.CanOne2OneUDS(canid[0], canid[1], cmd, cmdlen, Readbuf, 5003, Common.cmdmaxtime * 2, 3);
                        Sleep(50);
                        m_com.CanSendOneOnly(0x7DF, cmd_link, cmd_link[0] + 1);
                    }
                    Sleep(Common.waittime);
                    //错误处理
                    if (error == 5001) //通讯超时
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, getResources().getString(R.string.time_out), Common.Rnok);
                            break;
                        } else
                            continue;
                    } else if (error == 5002) //点击了返回
                    {
                        return;
                    } else if (error > 5000)//其他负响应
                    {
                        if (i > 8) {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            return;
                        } else
                            continue;
                    } else if (error < 100) //异常回复
                    {
                        if (i < 5) continue;
                        if ((Readbuf[1] & 0xFF) == 0x7F) //异常
                        {
                            ShowProcessList(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rnok);
                            break;
                        }
                    } else
                        ShowProcessListHide(Pid, step_name, Commonfunc.bytesToHexString(Readbuf, 0, Readbuf[0] + 1), Common.Rok);
                    //特殊处理返回结果
                    if (i == 34 || i == 35 || i == 36) {
                        byte[] v_soft = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_soft, 0, Readbuf[0] - 3);
                        String v_softver = new String(v_soft);
                        ShowProcessList(Pid, step_name, v_softver, Common.Rok);
                        if (t_printtemp == null)
                            t_printtemp = new ArrayList<String>();
                        t_printtemp.add(step_name + ": " + v_softver);
                    } else if (Readbuf[1] == 0x62) //读数据
                    {
                        byte[] v_data = new byte[Readbuf[0] - 3];
                        System.arraycopy(Readbuf, 4, v_data, 0, Readbuf[0] - 3);
                        String v_show = "";
                        String v_get = "";
                        int v_code = (Readbuf[2] & 0xFF) * 0x100 + (Readbuf[3] & 0xFF);
                        switch (v_code) {
                            case 0xF190:
                                v_show = new String(v_data);
                                v_get = new String(Common.cartype.vin);
                                break;
                            case 0xF187:
                                v_show = new String(v_data);
                                v_show = v_show.replace(" ", "");
                                v_show = v_show.trim();
                                v_get = "";
                                break;
                            case 0xF18A:
                                v_show = new String(v_data);
                                v_get = "";
                                break;
                        }
                        v_show = v_show.replace(" ", "");
                        v_show = v_show.trim();
                        if (v_get.length() > 0) {
                            if (v_show.equals(v_get))
                                ShowProcessList(Pid, step_name, v_show, Common.Rok);
                            else if (Common.cartype.OptMode == 1)
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rnull);
                            else {
                                ShowProcessList(Pid, step_name, v_show + "[" + v_get + "]", Common.Rok);
                            }
                        } else {
                            ShowProcessList(Pid, step_name, v_show, Common.Rnull);
                        }
                    } else if (i == 10 || i == 19 || i == 22) //结束下载driver
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x54) //清故障码
                    {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x59) //读故障码
                    {
                        //处理故障码
                        byte[] dtc = new byte[256];
                        dtc[0] = (byte) (((Readbuf[0] & 0xFF) - 3) / 4);
                        System.arraycopy(Readbuf, 4, dtc, 1, Readbuf[0] - 3);
                        ArrayList<Map<String, String>> dtclist = new ArrayList<Map<String, String>>();
                        ShowProcessList(Pid, step_name, "无故障", Common.Rok);
                    } else if (Readbuf[1] == 0x67 && Readbuf[2] == 0x03) //seed
                    {
                        System.arraycopy(Readbuf, 3, seed, 0, Readbuf[0] - 2);
                    } else if (Readbuf[1] == 0x74) {
                        v_maxlen = (Readbuf[3] & 0xFF) * 0x100 + (Readbuf[4] & 0xFF);
                    } else if (Readbuf[1] == 0x51) {
                        Sleep(1000);
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x03) {
                        if (Readbuf[5] == 0x03) {
                            i--;
                            Sleep(1000);
                        } else if (Readbuf[5] == 0x02) {
                            ShowProcessList(Pid, step_name, "", Common.Rok);
                        } else {
                            ShowProcessList(Pid, step_name, "" + (Readbuf[5] & 0xFF), Common.Rnok);
                            break;
                        }
                    } else if (Readbuf[1] == 0x71 && Readbuf[2] == 0x01) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    } else if (Readbuf[1] == 0x51) {
                        ShowProcessList(Pid, step_name, "", Common.Rok);
                        Sleep(1000);
                    }
                }
            }
        }

        //判断是否含有乱码
        public String isMessyCode(String strName) {
            Pattern p = Pattern.compile("\\s*|t*|r*|n*");
            Matcher m = p.matcher(strName);
            String after = m.replaceAll("");
            String temp = after.replaceAll("\\p{P}", "");
            char[] ch = temp.trim().toCharArray();
            for (int i = 0; i < ch.length; i++) {
                char c = ch[i];
                if (!Character.isLetterOrDigit(c)) {
                    if (!isChinese(c)) {//截取非乱码部分
                        return strName.substring(0, i);
                    }
                }
            }
            return strName;
        }

        public boolean isChinese(char c) {
            Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
            if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                    || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                    || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
                    || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                    || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
                return true;
            }
            return false;
        }

        ///////////////////////////////////////功能模块-end////////////////////////////////////////////////
    }

    private void Sleep(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return;
    }

    //参数：modename -- 模块名称;cmd -- 故障码数组，1byte（ num） + 4byte(高、中、低、状态) + ... ; DtcLen -- 单个故障码字节数
    private void GetDtcArray(String modename, byte[] cmd, ArrayList<Map<String, String>> list, int DtcLen) {
        int dtcnum = (cmd[0] & 0xFF);
        if (Common.Debug) Log.i(TAG, "DTC num:" + dtcnum);
        if (dtcnum == 0) return;
        byte[] code = new byte[3];
        Ini inidtc;
        try {
            inidtc = new Ini(new File(Common.cartype.dir_dtc));
            Profile.Section sec = inidtc.get(modename);
            //查找过滤DTC数组
            Profile.Section secfilter = inidtc.get(modename + "_FILTER");
            String v_num = null;
            if (secfilter != null)
                v_num = secfilter.get("NUM");
            int filternum = 0;
            if (v_num != null)
                filternum = Integer.valueOf(v_num);//过滤的故障码个数
            if (Common.Debug) Log.i(TAG, "Mode=" + modename + ",filternum =" + filternum);
            ArrayList<String> filterlistname = null;
            if (filternum > 0) {
                filterlistname = new ArrayList<String>(); //过滤数组
                for (int i = 0; i < filternum; i++) {
                    String data = secfilter.get("T" + (i + 1));
                    if (Common.Debug) Log.i(TAG, "i = " + i + "data = " + data);
                    if (data.length() < 5) continue;
                    filterlistname.add(data);
                }
            }
            for (int i = 0; i < dtcnum; i++) {
                if (Common.cartype.carmode_dir.equals("M1AEV")) {
                    if ("EPS1".equals(modename)) {
                        if (((cmd[i * 4] & 32) != 32) || ((cmd[i * 4] & 64) == 64)) {
                            continue;
                        }
                    } else if ("BMS1".equals(modename)) {

                    } else {
                        if (((cmd[i * 4] & 8) != 1) || ((cmd[i * 4] & 8) != 8)) {
                            continue;
                        }
                    }
                }
                System.arraycopy(cmd, 1 + i * 4, code, 0, 3); //负责dtc
                String pcode = GetPUBCCode(code, DtcLen); //getPCBUcode
                //比较是否被过滤
                if (filterlistname != null) {
                    int kk = 0;
                    for (kk = 0; kk < filterlistname.size(); kk++) {
                        if (pcode.equals(filterlistname.get(kk))) {
                            break;
                        }
                    }
                    if (kk < filterlistname.size())
                        continue;
                }
                HashMap<String, String> map = new HashMap<String, String>();
                String dtc = null;
                if (sec != null)
                    dtc = sec.get(pcode);
                if (dtc == null)
                    dtc = "ID未定义";
                else if (dtc.length() <= 0)
                    dtc = "ID未定义";
                //判断是否历史和当前
                //				if((status & 0xFF) == 0xFF) //当前
                //					dtc = "[已决]" + dtc;
                //				else
                //					dtc = "[未决]" + dtc;
                //pcode += "-" + Commonfunc.byteToHexString(status);
                map.put("NAME", pcode);
                if (Common.Debug) Log.i(TAG, "Dtc ID:" + pcode);
                map.put("CONTEXT", dtc);
                if (Common.Debug) Log.i(TAG, "Dtc Code:" + dtc);
                list.add(map);
            }
        } catch (InvalidFileFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private String GetPUBCCode(byte[] code, int dtclen) {
        String pcode = null;
        switch (code[0] & 0xC0) {
            case 0x00:
                pcode = "P";
                break;
            case 0x40:
                pcode = "C";
                break;
            case 0x80:
                pcode = "B";
                break;
            case 0xC0:
                pcode = "U";
                break;
            default:
                pcode = "P";
                break;
        }
        pcode += Commonfunc.byteToHexString((byte) (code[0] & 0x3F));
        pcode += Commonfunc.byteToHexString(code[1]);
        if (dtclen == 3)
            pcode += Commonfunc.byteToHexString(code[2]);
        return pcode;
    }
}
